feat(creator_name): add creator_name field to agents and knowledge bases for enhanced visibility
Introduced a new optional field, creator_name, in both CustomAgent and KnowledgeBase types to allow the front end to display the creator's name. This enhancement enables better differentiation between resources created by the current user and those created by other members of the same tenant. Updated relevant API handlers to populate this field during list operations, ensuring accurate representation in the UI. Additionally, modified the ResourceOriginBadge component to utilize the creator_name for improved context in resource listings. Refs: #1303
This commit is contained in:
@@ -99,6 +99,8 @@ export interface CustomAgent {
|
||||
is_builtin: boolean;
|
||||
tenant_id?: number;
|
||||
created_by?: string;
|
||||
// creator_name 由后端 list 接口批量回填,仅用于列表卡片来源徽章。
|
||||
creator_name?: string;
|
||||
config: CustomAgentConfig;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
|
||||
@@ -115,6 +115,9 @@ export interface KnowledgeBaseInfo {
|
||||
// Set by PR 5 of the multi-tenant RBAC series; nullable for legacy
|
||||
// KBs created before that migration backfilled the column.
|
||||
creator_id?: string
|
||||
// creator_name 由后端 list 接口批量回填(username 优先,退化到 email),
|
||||
// 仅用于列表卡片来源徽章;缺失代表无法解析(已删除 / 老数据)。
|
||||
creator_name?: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
document_count?: number
|
||||
|
||||
@@ -15,23 +15,30 @@ import { useAuthStore } from '@/stores/auth'
|
||||
* ResourceOriginBadge – a unified, compact label that explains *where* a
|
||||
* KB or Agent comes from. Replaces the ad-hoc "我的" / "shared-by-me-badge"
|
||||
* / org_name pills scattered across KnowledgeBaseList and AgentList. The
|
||||
* variants below cover the four origin shapes the list views actually
|
||||
* variants below cover the five origin shapes the list views actually
|
||||
* surface; future origins (e.g. "system" / "imported") should add a new
|
||||
* variant rather than re-using one of these.
|
||||
*
|
||||
* Variants:
|
||||
* - mine : created by the current user in the current tenant
|
||||
* - tenant : owned by the current tenant but created by someone else
|
||||
* — label shows tenant name; use when context doesn't say
|
||||
* - creator : same data shape as `tenant`, but the surrounding section
|
||||
* header already names the tenant ("本空间 · 仅查看"), so
|
||||
* the badge only carries the creator name to avoid the
|
||||
* duplicated "本空间 / wizardchen's Workspace" pill on
|
||||
* every card. Falls back to the i18n label when the
|
||||
* creator name is unknown.
|
||||
* - space : reached through a cross-tenant space (organization)
|
||||
* - shared : cross-tenant share without a useful org name to show
|
||||
*
|
||||
* Pass `creatorName` to surface "by 张三" in the tooltip for the `tenant`
|
||||
* variant; omit it for the `mine` / `space` / `shared` variants where the
|
||||
* subject is implicit.
|
||||
* variant, or to drive the visible label of the `creator` variant; omit it
|
||||
* for the `mine` / `space` / `shared` variants where the subject is implicit.
|
||||
*/
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
variant: 'mine' | 'tenant' | 'space' | 'shared'
|
||||
variant: 'mine' | 'tenant' | 'creator' | 'space' | 'shared'
|
||||
/** Used in `space` variant — the organization (space) display name. */
|
||||
spaceName?: string
|
||||
/** Optional creator display name, surfaces in tooltip for `tenant` variant. */
|
||||
@@ -51,6 +58,8 @@ const iconName = computed(() => {
|
||||
return 'user'
|
||||
case 'tenant':
|
||||
return 'usergroup'
|
||||
case 'creator':
|
||||
return 'user'
|
||||
case 'space':
|
||||
return 'building'
|
||||
case 'shared':
|
||||
@@ -70,6 +79,11 @@ const displayText = computed(() => {
|
||||
// Prefer the tenant name when known so the badge says where the
|
||||
// resource lives, not a vague "tenant" label. Falls back to i18n.
|
||||
return authStore.currentTenantName || t('resourceOrigin.tenant')
|
||||
case 'creator':
|
||||
// Section header already provides the「本空间」context, so we just
|
||||
// show who created it. Fall back to a generic label when the user
|
||||
// can't be resolved (creator_name 缺失,例如已删除账号 / 老数据)。
|
||||
return props.creatorName || t('resourceOrigin.tenant')
|
||||
case 'space':
|
||||
return props.spaceName || t('resourceOrigin.space')
|
||||
case 'shared':
|
||||
@@ -88,6 +102,12 @@ const tooltipText = computed(() => {
|
||||
return t('resourceOrigin.tenantTooltipWithCreator', { creator: props.creatorName })
|
||||
}
|
||||
return t('resourceOrigin.tenantTooltip')
|
||||
case 'creator':
|
||||
// 卡片标签只露名字;tooltip 把完整含义补回来。
|
||||
if (props.creatorName) {
|
||||
return t('resourceOrigin.tenantTooltipWithCreator', { creator: props.creatorName })
|
||||
}
|
||||
return t('resourceOrigin.tenantTooltip')
|
||||
case 'space':
|
||||
if (props.sourceTenantName) {
|
||||
return t('resourceOrigin.spaceTooltipWithTenant', {
|
||||
@@ -136,6 +156,11 @@ const tooltipText = computed(() => {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
}
|
||||
|
||||
&.origin-creator {
|
||||
color: var(--td-text-color-secondary);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
}
|
||||
|
||||
&.origin-space {
|
||||
color: var(--td-warning-color-7, #b86e02);
|
||||
background: var(--td-warning-color-1, #fff7e6);
|
||||
|
||||
@@ -425,6 +425,11 @@ export default {
|
||||
mine: 'My Agents',
|
||||
sharedToMe: 'Shared to Me',
|
||||
},
|
||||
sections: {
|
||||
tenantReadonly: 'Workspace · View only',
|
||||
sharedEditable: 'Shared with me · Can edit',
|
||||
sharedReadonly: 'Shared with me · View only',
|
||||
},
|
||||
empty: {
|
||||
title: 'No Custom Agents',
|
||||
description: 'Click the button in the top right to create your first agent',
|
||||
@@ -1618,6 +1623,9 @@ export default {
|
||||
sections: {
|
||||
pinned: 'Pinned',
|
||||
others: 'Others',
|
||||
tenantReadonly: 'Workspace · View only',
|
||||
sharedEditable: 'Shared with me · Can edit',
|
||||
sharedReadonly: 'Shared with me · View only',
|
||||
},
|
||||
messages: {
|
||||
deleted: 'Knowledge base deleted',
|
||||
|
||||
@@ -1317,6 +1317,11 @@ export default {
|
||||
mine: "내 에이전트",
|
||||
sharedToMe: "나와 공유됨",
|
||||
},
|
||||
sections: {
|
||||
tenantReadonly: "워크스페이스 · 읽기 전용",
|
||||
sharedEditable: "공유받음 · 편집 가능",
|
||||
sharedReadonly: "공유받음 · 읽기 전용",
|
||||
},
|
||||
empty: {
|
||||
title: "아직 맞춤 에이전트가 없습니다.",
|
||||
description: "첫 번째 에이전트를 생성하려면 오른쪽 상단에 있는 버튼을 클릭하세요.",
|
||||
@@ -2276,6 +2281,9 @@ export default {
|
||||
sections: {
|
||||
pinned: "고정됨",
|
||||
others: "기타",
|
||||
tenantReadonly: "워크스페이스 · 읽기 전용",
|
||||
sharedEditable: "공유받음 · 편집 가능",
|
||||
sharedReadonly: "공유받음 · 읽기 전용",
|
||||
},
|
||||
detail: {
|
||||
title: "공유 지식베이스",
|
||||
|
||||
@@ -517,6 +517,11 @@ export default {
|
||||
mine: 'My Agents',
|
||||
sharedToMe: 'Shared to Me'
|
||||
},
|
||||
sections: {
|
||||
tenantReadonly: 'Рабочая область · Только просмотр',
|
||||
sharedEditable: 'Доступно мне · Можно редактировать',
|
||||
sharedReadonly: 'Доступно мне · Только просмотр'
|
||||
},
|
||||
empty: {
|
||||
title: 'No Custom Agents',
|
||||
description: 'Click the button in the top right to create your first agent',
|
||||
@@ -1850,7 +1855,10 @@ export default {
|
||||
},
|
||||
sections: {
|
||||
pinned: 'Закреплённые',
|
||||
others: 'Другие'
|
||||
others: 'Другие',
|
||||
tenantReadonly: 'Рабочая область · Только просмотр',
|
||||
sharedEditable: 'Доступно мне · Можно редактировать',
|
||||
sharedReadonly: 'Доступно мне · Только просмотр'
|
||||
},
|
||||
messages: {
|
||||
deleted: 'База знаний удалена',
|
||||
|
||||
@@ -1311,6 +1311,11 @@ export default {
|
||||
mine: "我的智能体",
|
||||
sharedToMe: "共享给我",
|
||||
},
|
||||
sections: {
|
||||
tenantReadonly: "本空间 · 仅查看",
|
||||
sharedEditable: "共享给我 · 可编辑",
|
||||
sharedReadonly: "共享给我 · 仅查看",
|
||||
},
|
||||
empty: {
|
||||
title: "暂无自定义智能体",
|
||||
description: "点击右上角按钮创建您的第一个智能体",
|
||||
@@ -2252,6 +2257,9 @@ export default {
|
||||
sections: {
|
||||
pinned: "置顶",
|
||||
others: "其他",
|
||||
tenantReadonly: "本空间 · 仅查看",
|
||||
sharedEditable: "共享给我 · 可编辑",
|
||||
sharedReadonly: "共享给我 · 仅查看",
|
||||
},
|
||||
detail: {
|
||||
title: "共享知识库",
|
||||
|
||||
@@ -64,402 +64,457 @@
|
||||
<div
|
||||
v-if="(spaceSelection === 'all' || spaceSelection === 'favorites' || spaceSelection === 'recents') && filteredAgents.length > 0"
|
||||
class="agent-card-wrap">
|
||||
<div v-for="agent in filteredAgents" :key="agent.isMine ? agent.id : `shared-${agent.share_id}`"
|
||||
class="agent-card" :class="{
|
||||
<template v-for="(agent, index) in filteredAgents"
|
||||
:key="agent.isMine ? agent.id : `shared-${agent.share_id}`">
|
||||
<!-- 本空间 · 仅查看:本租户里我无法编辑的(同事创建 / 内建),
|
||||
仅在「全部」视图、contributor 角色下出现 -->
|
||||
<div v-if="spaceSelection === 'all'
|
||||
&& showShareGroupHeaders
|
||||
&& agent.isMine
|
||||
&& !isMyAgent(agent)
|
||||
&& (index === 0
|
||||
|| !filteredAgents[index - 1].isMine
|
||||
|| isMyAgent(filteredAgents[index - 1] as AgentWithUI))" class="agent-section-header">
|
||||
<span>{{ $t('agent.sections.tenantReadonly') }}</span>
|
||||
</div>
|
||||
<!-- 共享给我 · 可编辑:仅在「全部」视图过渡处显示分组标题 -->
|
||||
<div v-if="spaceSelection === 'all'
|
||||
&& showShareGroupHeaders
|
||||
&& !agent.isMine
|
||||
&& isSharedAgentEditable((agent as any).permission)
|
||||
&& (index === 0 || filteredAgents[index - 1].isMine)" class="agent-section-header">
|
||||
<span>{{ $t('agent.sections.sharedEditable') }}</span>
|
||||
</div>
|
||||
<!-- 共享给我 · 仅查看 -->
|
||||
<div v-if="spaceSelection === 'all'
|
||||
&& showShareGroupHeaders
|
||||
&& !agent.isMine
|
||||
&& !isSharedAgentEditable((agent as any).permission)
|
||||
&& (index === 0
|
||||
|| filteredAgents[index - 1].isMine
|
||||
|| isSharedAgentEditable((filteredAgents[index - 1] as any).permission))" class="agent-section-header">
|
||||
<span>{{ $t('agent.sections.sharedReadonly') }}</span>
|
||||
</div>
|
||||
<div class="agent-card" :class="{
|
||||
'is-builtin': agent.is_builtin,
|
||||
'agent-mode-normal': agent.config?.agent_mode === 'quick-answer',
|
||||
'agent-mode-agent': agent.config?.agent_mode === 'smart-reasoning',
|
||||
'shared-agent-card': !agent.isMine
|
||||
}" @click="handleCardClick(agent)">
|
||||
<!-- 收藏按钮 -->
|
||||
<button type="button" class="agent-favorite-star" :class="{ 'is-favorited': isAgentFavorited(agent.id) }"
|
||||
@click.stop="toggleFavoriteAgent(agent.id, $event)">
|
||||
<t-icon :name="isAgentFavorited(agent.id) ? 'star-filled' : 'star'" size="14px" />
|
||||
</button>
|
||||
<!-- 装饰星星 -->
|
||||
<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">
|
||||
<path
|
||||
d="M10 3L10.8 6.2C10.9 6.7 11.3 7.1 11.8 7.2L15 8L11.8 8.8C11.3 8.9 10.9 9.3 10.8 9.8L10 13L9.2 9.8C9.1 9.3 8.7 8.9 8.2 8.8L5 8L8.2 7.2C8.7 7.1 9.1 6.7 9.2 6.2L10 3Z"
|
||||
stroke="currentColor" stroke-width="0.8" stroke-linecap="round" stroke-linejoin="round"
|
||||
fill="currentColor" fill-opacity="0.15" />
|
||||
</svg>
|
||||
<svg class="star-icon small" width="14" height="14" viewBox="0 0 20 20" fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M10 3L10.8 6.2C10.9 6.7 11.3 7.1 11.8 7.2L15 8L11.8 8.8C11.3 8.9 10.9 9.3 10.8 9.8L10 13L9.2 9.8C9.1 9.3 8.7 8.9 8.2 8.8L5 8L8.2 7.2C8.7 7.1 9.1 6.7 9.2 6.2L10 3Z"
|
||||
stroke="currentColor" stroke-width="0.8" stroke-linecap="round" stroke-linejoin="round"
|
||||
fill="currentColor" fill-opacity="0.15" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="card-header">
|
||||
<div class="card-header-left">
|
||||
<div v-if="agent.is_builtin" class="builtin-avatar"
|
||||
:class="agent.config?.agent_mode === 'smart-reasoning' ? 'agent' : 'normal'">
|
||||
<t-icon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'"
|
||||
size="18px" />
|
||||
</div>
|
||||
<div v-else-if="agent.avatar" class="builtin-avatar agent-emoji">{{ agent.avatar }}</div>
|
||||
<AgentAvatar v-else :name="agent.name" size="small" />
|
||||
<span class="card-title" :title="agent.name">{{ agent.name }}</span>
|
||||
<!-- 收藏按钮 -->
|
||||
<button type="button" class="agent-favorite-star" :class="{ 'is-favorited': isAgentFavorited(agent.id) }"
|
||||
@click.stop="toggleFavoriteAgent(agent.id, $event)">
|
||||
<t-icon :name="isAgentFavorited(agent.id) ? 'star-filled' : 'star'" size="14px" />
|
||||
</button>
|
||||
<!-- 装饰星星 -->
|
||||
<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">
|
||||
<path
|
||||
d="M10 3L10.8 6.2C10.9 6.7 11.3 7.1 11.8 7.2L15 8L11.8 8.8C11.3 8.9 10.9 9.3 10.8 9.8L10 13L9.2 9.8C9.1 9.3 8.7 8.9 8.2 8.8L5 8L8.2 7.2C8.7 7.1 9.1 6.7 9.2 6.2L10 3Z"
|
||||
stroke="currentColor" stroke-width="0.8" stroke-linecap="round" stroke-linejoin="round"
|
||||
fill="currentColor" fill-opacity="0.15" />
|
||||
</svg>
|
||||
<svg class="star-icon small" width="14" height="14" viewBox="0 0 20 20" fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M10 3L10.8 6.2C10.9 6.7 11.3 7.1 11.8 7.2L15 8L11.8 8.8C11.3 8.9 10.9 9.3 10.8 9.8L10 13L9.2 9.8C9.1 9.3 8.7 8.9 8.2 8.8L5 8L8.2 7.2C8.7 7.1 9.1 6.7 9.2 6.2L10 3Z"
|
||||
stroke="currentColor" stroke-width="0.8" stroke-linecap="round" stroke-linejoin="round"
|
||||
fill="currentColor" fill-opacity="0.15" />
|
||||
</svg>
|
||||
</div>
|
||||
<t-popup
|
||||
v-if="agent.isMine && (canManageAgent(agent) || authStore.hasRole('contributor') || (!agent.is_builtin && authStore.hasRole('admin')))"
|
||||
:visible="openMoreAgentId === agent.id" trigger="hover" overlayClassName="card-more-popup"
|
||||
destroy-on-close placement="bottom-right" @visible-change="onVisibleChange"
|
||||
@update:visible="(v: boolean) => { if (!v) openMoreAgentId = null }">
|
||||
<div class="more-wrap" :class="{ 'active-more': openMoreAgentId === agent.id }"
|
||||
@click="toggleMore($event, agent.id)">
|
||||
<img class="more-icon" src="@/assets/img/more.png" alt="" />
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="popup-menu">
|
||||
<div v-if="canManageAgent(agent)" class="popup-menu-item" @click="handleEdit(agent)"><t-icon
|
||||
class="menu-icon" name="edit" /><span>{{ $t('common.edit') }}</span></div>
|
||||
<div v-if="authStore.hasRole('contributor')" class="popup-menu-item" @click="handleCopy(agent)">
|
||||
<t-icon class="menu-icon" name="file-copy" /><span>{{ $t('common.copy') }}</span>
|
||||
</div>
|
||||
<div v-if="!agent.is_builtin && authStore.hasRole('admin')" class="popup-menu-item"
|
||||
@click="handleToggleDisabled(agent)">
|
||||
<t-icon class="menu-icon" name="poweroff" />
|
||||
<span>{{ agent.disabled_by_me ? $t('agent.enable') : $t('agent.disable') }}</span>
|
||||
</div>
|
||||
<div v-if="!agent.is_builtin && canManageAgent(agent)" class="popup-menu-item delete"
|
||||
@click="handleDelete(agent)"><t-icon class="menu-icon" name="delete" /><span>{{
|
||||
$t('common.delete') }}</span></div>
|
||||
<div class="card-header">
|
||||
<div class="card-header-left">
|
||||
<div v-if="agent.is_builtin" class="builtin-avatar"
|
||||
:class="agent.config?.agent_mode === 'smart-reasoning' ? 'agent' : 'normal'">
|
||||
<t-icon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'"
|
||||
size="18px" />
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
<t-popup v-else-if="!agent.isMine && authStore.hasRole('admin')"
|
||||
:visible="openMoreAgentId === 'shared-' + agent.share_id" trigger="hover"
|
||||
overlayClassName="card-more-popup" destroy-on-close placement="bottom-right"
|
||||
@update:visible="(v: boolean) => { if (!v) openMoreAgentId = null }">
|
||||
<div class="more-wrap" :class="{ 'active-more': openMoreAgentId === 'shared-' + agent.share_id }"
|
||||
@click.stop="toggleMore($event, 'shared-' + agent.share_id)">
|
||||
<img class="more-icon" src="@/assets/img/more.png" alt="" />
|
||||
<div v-else-if="agent.avatar" class="builtin-avatar agent-emoji">{{ agent.avatar }}</div>
|
||||
<AgentAvatar v-else :name="agent.name" size="small" />
|
||||
<span class="card-title" :title="agent.name">{{ agent.name }}</span>
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="popup-menu">
|
||||
<div class="popup-menu-item" @click="handleToggleSharedDisabled(agent)">
|
||||
<t-icon class="menu-icon" name="poweroff" />
|
||||
<span>{{ agent.disabled_by_me ? $t('agent.enable') : $t('agent.disable') }}</span>
|
||||
</div>
|
||||
<t-popup
|
||||
v-if="agent.isMine && (canManageAgent(agent) || authStore.hasRole('contributor') || (!agent.is_builtin && authStore.hasRole('admin')))"
|
||||
:visible="openMoreAgentId === agent.id" trigger="hover" overlayClassName="card-more-popup"
|
||||
destroy-on-close placement="bottom-right" @visible-change="onVisibleChange"
|
||||
@update:visible="(v: boolean) => { if (!v) openMoreAgentId = null }">
|
||||
<div class="more-wrap" :class="{ 'active-more': openMoreAgentId === agent.id }"
|
||||
@click="toggleMore($event, agent.id)">
|
||||
<img class="more-icon" src="@/assets/img/more.png" alt="" />
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="card-description">{{ agent.description || $t('agent.noDescription') }}</div>
|
||||
</div>
|
||||
<div class="card-bottom">
|
||||
<div class="bottom-left">
|
||||
<div class="feature-badges">
|
||||
<t-tag v-if="agent.isMine && !agent.is_builtin && agent.disabled_by_me" theme="default" size="small"
|
||||
class="disabled-badge">{{ $t('agent.disabled') }}</t-tag>
|
||||
<t-tag v-if="!agent.isMine && agent.disabled_by_me" theme="default" size="small"
|
||||
class="disabled-badge">{{
|
||||
$t('agent.disabled') }}</t-tag>
|
||||
<t-tooltip
|
||||
:content="agent.config?.agent_mode === 'smart-reasoning' ? $t('agent.mode.agent') : $t('agent.mode.normal')"
|
||||
placement="top">
|
||||
<div class="feature-badge"
|
||||
:class="{ 'mode-normal': agent.config?.agent_mode === 'quick-answer', 'mode-agent': agent.config?.agent_mode === 'smart-reasoning' }">
|
||||
<t-icon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'"
|
||||
size="14px" />
|
||||
<template #content>
|
||||
<div class="popup-menu">
|
||||
<div v-if="canManageAgent(agent)" class="popup-menu-item" @click="handleEdit(agent)"><t-icon
|
||||
class="menu-icon" name="edit" /><span>{{ $t('common.edit') }}</span></div>
|
||||
<div v-if="authStore.hasRole('contributor')" class="popup-menu-item" @click="handleCopy(agent)">
|
||||
<t-icon class="menu-icon" name="file-copy" /><span>{{ $t('common.copy') }}</span>
|
||||
</div>
|
||||
<div v-if="!agent.is_builtin && authStore.hasRole('admin')" class="popup-menu-item"
|
||||
@click="handleToggleDisabled(agent)">
|
||||
<t-icon class="menu-icon" name="poweroff" />
|
||||
<span>{{ agent.disabled_by_me ? $t('agent.enable') : $t('agent.disable') }}</span>
|
||||
</div>
|
||||
<div v-if="!agent.is_builtin && canManageAgent(agent)" class="popup-menu-item delete"
|
||||
@click="handleDelete(agent)"><t-icon class="menu-icon" name="delete" /><span>{{
|
||||
$t('common.delete') }}</span></div>
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="agent.config?.web_search_enabled" :content="$t('agent.features.webSearch')"
|
||||
placement="top">
|
||||
<div class="feature-badge web-search">
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="8" cy="8" r="6" stroke="currentColor" stroke-width="1.2" fill="none" />
|
||||
<ellipse cx="8" cy="8" rx="2.5" ry="6" stroke="currentColor" stroke-width="1.2" fill="none" />
|
||||
<line x1="2" y1="6" x2="14" y2="6" stroke="currentColor" stroke-width="1.2" />
|
||||
<line x1="2" y1="10" x2="14" y2="10" stroke="currentColor" stroke-width="1.2" />
|
||||
</svg>
|
||||
</template>
|
||||
</t-popup>
|
||||
<t-popup v-else-if="!agent.isMine && authStore.hasRole('admin')"
|
||||
:visible="openMoreAgentId === 'shared-' + agent.share_id" trigger="hover"
|
||||
overlayClassName="card-more-popup" destroy-on-close placement="bottom-right"
|
||||
@update:visible="(v: boolean) => { if (!v) openMoreAgentId = null }">
|
||||
<div class="more-wrap" :class="{ 'active-more': openMoreAgentId === 'shared-' + agent.share_id }"
|
||||
@click.stop="toggleMore($event, 'shared-' + agent.share_id)">
|
||||
<img class="more-icon" src="@/assets/img/more.png" alt="" />
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="popup-menu">
|
||||
<div class="popup-menu-item" @click="handleToggleSharedDisabled(agent)">
|
||||
<t-icon class="menu-icon" name="poweroff" />
|
||||
<span>{{ agent.disabled_by_me ? $t('agent.enable') : $t('agent.disable') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="agent.config?.knowledge_bases?.length || agent.config?.kb_selection_mode === 'all'"
|
||||
:content="$t('agent.features.knowledgeBase')" placement="top">
|
||||
<div class="feature-badge knowledge">
|
||||
<t-icon name="folder" size="16px" />
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="agent.config?.mcp_services?.length || agent.config?.mcp_selection_mode === 'all'"
|
||||
:content="$t('agent.features.mcp')" placement="top">
|
||||
<div class="feature-badge mcp">
|
||||
<t-icon name="extension" size="16px" />
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="agent.config?.multi_turn_enabled" :content="$t('agent.features.multiTurn')"
|
||||
placement="top">
|
||||
<div class="feature-badge multi-turn">
|
||||
<t-icon name="chat-bubble" size="16px" />
|
||||
</div>
|
||||
</t-tooltip>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="card-description">{{ agent.description || $t('agent.noDescription') }}</div>
|
||||
</div>
|
||||
<div class="card-bottom">
|
||||
<div class="bottom-left">
|
||||
<div class="feature-badges">
|
||||
<t-tag v-if="agent.isMine && !agent.is_builtin && agent.disabled_by_me" theme="default" size="small"
|
||||
class="disabled-badge">{{ $t('agent.disabled') }}</t-tag>
|
||||
<t-tag v-if="!agent.isMine && agent.disabled_by_me" theme="default" size="small"
|
||||
class="disabled-badge">{{
|
||||
$t('agent.disabled') }}</t-tag>
|
||||
<t-tooltip
|
||||
:content="agent.config?.agent_mode === 'smart-reasoning' ? $t('agent.mode.agent') : $t('agent.mode.normal')"
|
||||
placement="top">
|
||||
<div class="feature-badge"
|
||||
:class="{ 'mode-normal': agent.config?.agent_mode === 'quick-answer', 'mode-agent': agent.config?.agent_mode === 'smart-reasoning' }">
|
||||
<t-icon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'"
|
||||
size="14px" />
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="agent.config?.web_search_enabled" :content="$t('agent.features.webSearch')"
|
||||
placement="top">
|
||||
<div class="feature-badge web-search">
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="8" cy="8" r="6" stroke="currentColor" stroke-width="1.2" fill="none" />
|
||||
<ellipse cx="8" cy="8" rx="2.5" ry="6" stroke="currentColor" stroke-width="1.2" fill="none" />
|
||||
<line x1="2" y1="6" x2="14" y2="6" stroke="currentColor" stroke-width="1.2" />
|
||||
<line x1="2" y1="10" x2="14" y2="10" stroke="currentColor" stroke-width="1.2" />
|
||||
</svg>
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="agent.config?.knowledge_bases?.length || agent.config?.kb_selection_mode === 'all'"
|
||||
:content="$t('agent.features.knowledgeBase')" placement="top">
|
||||
<div class="feature-badge knowledge">
|
||||
<t-icon name="folder" size="16px" />
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="agent.config?.mcp_services?.length || agent.config?.mcp_selection_mode === 'all'"
|
||||
:content="$t('agent.features.mcp')" placement="top">
|
||||
<div class="feature-badge mcp">
|
||||
<t-icon name="extension" size="16px" />
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="agent.config?.multi_turn_enabled" :content="$t('agent.features.multiTurn')"
|
||||
placement="top">
|
||||
<div class="feature-badge multi-turn">
|
||||
<t-icon name="chat-bubble" size="16px" />
|
||||
</div>
|
||||
</t-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 右下角:内置 / 自定义 / 空间图标+名称 -->
|
||||
<div v-if="!agent.isMine" class="card-bottom-source">
|
||||
<img src="@/assets/img/organization-green.svg" class="org-icon" alt="" aria-hidden="true" />
|
||||
<span class="org-source-text">{{ agent.org_name }}</span>
|
||||
</div>
|
||||
<div v-else-if="agent.is_builtin" class="builtin-badge">
|
||||
<t-icon name="lock-on" size="12px" />
|
||||
<span>{{ $t('agent.builtin') }}</span>
|
||||
</div>
|
||||
<div v-else class="custom-badge">
|
||||
<span>{{ $t('agent.type.custom') }}</span>
|
||||
<!-- 右下角:内置 / 来源徽章 / 空间图标+名称 -->
|
||||
<div v-if="!agent.isMine" class="card-bottom-source">
|
||||
<img src="@/assets/img/organization-green.svg" class="org-icon" alt="" aria-hidden="true" />
|
||||
<span class="org-source-text">{{ agent.org_name }}</span>
|
||||
</div>
|
||||
<div v-else-if="agent.is_builtin" class="builtin-badge">
|
||||
<t-icon name="lock-on" size="12px" />
|
||||
<span>{{ $t('agent.builtin') }}</span>
|
||||
</div>
|
||||
<ResourceOriginBadge v-else :variant="agentOriginVariant(agent)"
|
||||
:creator-name="(agent as any).creator_name" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- 我的智能体 -->
|
||||
<div v-if="spaceSelection === 'mine' && agents.length > 0" class="agent-card-wrap">
|
||||
<div v-for="agent in agents" :key="agent.id" class="agent-card" :class="{
|
||||
'is-builtin': agent.is_builtin,
|
||||
'agent-mode-normal': agent.config?.agent_mode === 'quick-answer',
|
||||
'agent-mode-agent': agent.config?.agent_mode === 'smart-reasoning'
|
||||
}" @click="handleCardClick(agent)">
|
||||
<!-- 收藏按钮 -->
|
||||
<button type="button" class="agent-favorite-star" :class="{ 'is-favorited': isAgentFavorited(agent.id) }"
|
||||
@click.stop="toggleFavoriteAgent(agent.id, $event)">
|
||||
<t-icon :name="isAgentFavorited(agent.id) ? 'star-filled' : 'star'" size="14px" />
|
||||
</button>
|
||||
<!-- 装饰星星 -->
|
||||
<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">
|
||||
<path
|
||||
d="M10 3L10.8 6.2C10.9 6.7 11.3 7.1 11.8 7.2L15 8L11.8 8.8C11.3 8.9 10.9 9.3 10.8 9.8L10 13L9.2 9.8C9.1 9.3 8.7 8.9 8.2 8.8L5 8L8.2 7.2C8.7 7.1 9.1 6.7 9.2 6.2L10 3Z"
|
||||
stroke="currentColor" stroke-width="0.8" stroke-linecap="round" stroke-linejoin="round"
|
||||
fill="currentColor" fill-opacity="0.15" />
|
||||
</svg>
|
||||
<svg class="star-icon small" width="14" height="14" viewBox="0 0 20 20" fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M10 3L10.8 6.2C10.9 6.7 11.3 7.1 11.8 7.2L15 8L11.8 8.8C11.3 8.9 10.9 9.3 10.8 9.8L10 13L9.2 9.8C9.1 9.3 8.7 8.9 8.2 8.8L5 8L8.2 7.2C8.7 7.1 9.1 6.7 9.2 6.2L10 3Z"
|
||||
stroke="currentColor" stroke-width="0.8" stroke-linecap="round" stroke-linejoin="round"
|
||||
fill="currentColor" fill-opacity="0.15" />
|
||||
</svg>
|
||||
<div v-if="spaceSelection === 'mine' && sortedMineAgents.length > 0" class="agent-card-wrap">
|
||||
<template v-for="(agent, index) in sortedMineAgents" :key="agent.id">
|
||||
<!-- 本空间 · 仅查看:从「我创建」首次过渡到「同事创建 / 内建」 -->
|
||||
<div v-if="showShareGroupHeaders
|
||||
&& !isMyAgent(agent)
|
||||
&& (index === 0 || isMyAgent(sortedMineAgents[index - 1]))" class="agent-section-header">
|
||||
<span>{{ $t('agent.sections.tenantReadonly') }}</span>
|
||||
</div>
|
||||
|
||||
<!-- 卡片头部 -->
|
||||
<div class="card-header">
|
||||
<div class="card-header-left">
|
||||
<!-- 内置智能体使用简洁图标 -->
|
||||
<div v-if="agent.is_builtin" class="builtin-avatar"
|
||||
:class="agent.config?.agent_mode === 'smart-reasoning' ? 'agent' : 'normal'">
|
||||
<t-icon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'"
|
||||
size="18px" />
|
||||
</div>
|
||||
<div v-else-if="agent.avatar" class="builtin-avatar agent-emoji">{{ agent.avatar }}</div>
|
||||
<AgentAvatar v-else :name="agent.name" size="small" />
|
||||
<span class="card-title" :title="agent.name">{{ agent.name }}</span>
|
||||
<div class="agent-card" :class="{
|
||||
'is-builtin': agent.is_builtin,
|
||||
'agent-mode-normal': agent.config?.agent_mode === 'quick-answer',
|
||||
'agent-mode-agent': agent.config?.agent_mode === 'smart-reasoning'
|
||||
}" @click="handleCardClick(agent)">
|
||||
<!-- 收藏按钮 -->
|
||||
<button type="button" class="agent-favorite-star" :class="{ 'is-favorited': isAgentFavorited(agent.id) }"
|
||||
@click.stop="toggleFavoriteAgent(agent.id, $event)">
|
||||
<t-icon :name="isAgentFavorited(agent.id) ? 'star-filled' : 'star'" size="14px" />
|
||||
</button>
|
||||
<!-- 装饰星星 -->
|
||||
<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">
|
||||
<path
|
||||
d="M10 3L10.8 6.2C10.9 6.7 11.3 7.1 11.8 7.2L15 8L11.8 8.8C11.3 8.9 10.9 9.3 10.8 9.8L10 13L9.2 9.8C9.1 9.3 8.7 8.9 8.2 8.8L5 8L8.2 7.2C8.7 7.1 9.1 6.7 9.2 6.2L10 3Z"
|
||||
stroke="currentColor" stroke-width="0.8" stroke-linecap="round" stroke-linejoin="round"
|
||||
fill="currentColor" fill-opacity="0.15" />
|
||||
</svg>
|
||||
<svg class="star-icon small" width="14" height="14" viewBox="0 0 20 20" fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M10 3L10.8 6.2C10.9 6.7 11.3 7.1 11.8 7.2L15 8L11.8 8.8C11.3 8.9 10.9 9.3 10.8 9.8L10 13L9.2 9.8C9.1 9.3 8.7 8.9 8.2 8.8L5 8L8.2 7.2C8.7 7.1 9.1 6.7 9.2 6.2L10 3Z"
|
||||
stroke="currentColor" stroke-width="0.8" stroke-linecap="round" stroke-linejoin="round"
|
||||
fill="currentColor" fill-opacity="0.15" />
|
||||
</svg>
|
||||
</div>
|
||||
<t-popup
|
||||
v-if="canManageAgent(agent) || authStore.hasRole('contributor') || (!agent.is_builtin && authStore.hasRole('admin'))"
|
||||
:visible="openMoreAgentId === agent.id" trigger="hover" overlayClassName="card-more-popup"
|
||||
destroy-on-close placement="bottom-right" @visible-change="onVisibleChange"
|
||||
@update:visible="(v: boolean) => { if (!v) openMoreAgentId = null }">
|
||||
<div class="more-wrap" :class="{ 'active-more': openMoreAgentId === agent.id }"
|
||||
@click="toggleMore($event, agent.id)">
|
||||
<img class="more-icon" src="@/assets/img/more.png" alt="" />
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="popup-menu">
|
||||
<div v-if="canManageAgent(agent)" class="popup-menu-item" @click="handleEdit(agent)">
|
||||
<t-icon class="menu-icon" name="edit" />
|
||||
<span>{{ $t('common.edit') }}</span>
|
||||
</div>
|
||||
<div v-if="authStore.hasRole('contributor')" class="popup-menu-item" @click="handleCopy(agent)">
|
||||
<t-icon class="menu-icon" name="file-copy" />
|
||||
<span>{{ $t('common.copy') }}</span>
|
||||
</div>
|
||||
<div v-if="!agent.is_builtin && authStore.hasRole('admin')" class="popup-menu-item"
|
||||
@click="handleToggleDisabled(agent)">
|
||||
<t-icon class="menu-icon" name="poweroff" />
|
||||
<span>{{ agent.disabled_by_me ? $t('agent.enable') : $t('agent.disable') }}</span>
|
||||
</div>
|
||||
<div v-if="!agent.is_builtin && canManageAgent(agent)" class="popup-menu-item delete"
|
||||
@click="handleDelete(agent)">
|
||||
<t-icon class="menu-icon" name="delete" />
|
||||
<span>{{ $t('common.delete') }}</span>
|
||||
</div>
|
||||
|
||||
<!-- 卡片头部 -->
|
||||
<div class="card-header">
|
||||
<div class="card-header-left">
|
||||
<!-- 内置智能体使用简洁图标 -->
|
||||
<div v-if="agent.is_builtin" class="builtin-avatar"
|
||||
:class="agent.config?.agent_mode === 'smart-reasoning' ? 'agent' : 'normal'">
|
||||
<t-icon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'"
|
||||
size="18px" />
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
|
||||
<!-- 卡片内容 -->
|
||||
<div class="card-content">
|
||||
<div class="card-description">
|
||||
{{ agent.description || $t('agent.noDescription') }}
|
||||
<div v-else-if="agent.avatar" class="builtin-avatar agent-emoji">{{ agent.avatar }}</div>
|
||||
<AgentAvatar v-else :name="agent.name" size="small" />
|
||||
<span class="card-title" :title="agent.name">{{ agent.name }}</span>
|
||||
</div>
|
||||
<t-popup
|
||||
v-if="canManageAgent(agent) || authStore.hasRole('contributor') || (!agent.is_builtin && authStore.hasRole('admin'))"
|
||||
:visible="openMoreAgentId === agent.id" trigger="hover" overlayClassName="card-more-popup"
|
||||
destroy-on-close placement="bottom-right" @visible-change="onVisibleChange"
|
||||
@update:visible="(v: boolean) => { if (!v) openMoreAgentId = null }">
|
||||
<div class="more-wrap" :class="{ 'active-more': openMoreAgentId === agent.id }"
|
||||
@click="toggleMore($event, agent.id)">
|
||||
<img class="more-icon" src="@/assets/img/more.png" alt="" />
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="popup-menu">
|
||||
<div v-if="canManageAgent(agent)" class="popup-menu-item" @click="handleEdit(agent)">
|
||||
<t-icon class="menu-icon" name="edit" />
|
||||
<span>{{ $t('common.edit') }}</span>
|
||||
</div>
|
||||
<div v-if="authStore.hasRole('contributor')" class="popup-menu-item" @click="handleCopy(agent)">
|
||||
<t-icon class="menu-icon" name="file-copy" />
|
||||
<span>{{ $t('common.copy') }}</span>
|
||||
</div>
|
||||
<div v-if="!agent.is_builtin && authStore.hasRole('admin')" class="popup-menu-item"
|
||||
@click="handleToggleDisabled(agent)">
|
||||
<t-icon class="menu-icon" name="poweroff" />
|
||||
<span>{{ agent.disabled_by_me ? $t('agent.enable') : $t('agent.disable') }}</span>
|
||||
</div>
|
||||
<div v-if="!agent.is_builtin && canManageAgent(agent)" class="popup-menu-item delete"
|
||||
@click="handleDelete(agent)">
|
||||
<t-icon class="menu-icon" name="delete" />
|
||||
<span>{{ $t('common.delete') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 卡片底部 -->
|
||||
<div class="card-bottom">
|
||||
<div class="bottom-left">
|
||||
<div class="feature-badges">
|
||||
<t-tag v-if="!agent.is_builtin && agent.disabled_by_me" theme="default" size="small"
|
||||
class="disabled-badge">{{ $t('agent.disabled') }}</t-tag>
|
||||
<t-tooltip
|
||||
:content="agent.config?.agent_mode === 'smart-reasoning' ? $t('agent.mode.agent') : $t('agent.mode.normal')"
|
||||
placement="top">
|
||||
<div class="feature-badge"
|
||||
:class="{ 'mode-normal': agent.config?.agent_mode === 'quick-answer', 'mode-agent': agent.config?.agent_mode === 'smart-reasoning' }">
|
||||
<t-icon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'"
|
||||
size="14px" />
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="agent.config?.web_search_enabled" :content="$t('agent.features.webSearch')"
|
||||
placement="top">
|
||||
<div class="feature-badge web-search">
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="8" cy="8" r="6" stroke="currentColor" stroke-width="1.2" fill="none" />
|
||||
<ellipse cx="8" cy="8" rx="2.5" ry="6" stroke="currentColor" stroke-width="1.2" fill="none" />
|
||||
<line x1="2" y1="6" x2="14" y2="6" stroke="currentColor" stroke-width="1.2" />
|
||||
<line x1="2" y1="10" x2="14" y2="10" stroke="currentColor" stroke-width="1.2" />
|
||||
</svg>
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="agent.config?.knowledge_bases?.length || agent.config?.kb_selection_mode === 'all'"
|
||||
:content="$t('agent.features.knowledgeBase')" placement="top">
|
||||
<div class="feature-badge knowledge">
|
||||
<t-icon name="folder" size="16px" />
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="agent.config?.mcp_services?.length || agent.config?.mcp_selection_mode === 'all'"
|
||||
:content="$t('agent.features.mcp')" placement="top">
|
||||
<div class="feature-badge mcp">
|
||||
<t-icon name="extension" size="16px" />
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="agent.config?.multi_turn_enabled" :content="$t('agent.features.multiTurn')"
|
||||
placement="top">
|
||||
<div class="feature-badge multi-turn">
|
||||
<t-icon name="chat-bubble" size="16px" />
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<!-- 卡片内容 -->
|
||||
<div class="card-content">
|
||||
<div class="card-description">
|
||||
{{ agent.description || $t('agent.noDescription') }}
|
||||
</div>
|
||||
</div>
|
||||
<!-- 右下角:内置 / 自定义 -->
|
||||
<div v-if="agent.is_builtin" class="builtin-badge">
|
||||
<t-icon name="lock-on" size="12px" />
|
||||
<span>{{ $t('agent.builtin') }}</span>
|
||||
</div>
|
||||
<div v-else class="custom-badge">
|
||||
<span>{{ $t('agent.type.custom') }}</span>
|
||||
|
||||
<!-- 卡片底部 -->
|
||||
<div class="card-bottom">
|
||||
<div class="bottom-left">
|
||||
<div class="feature-badges">
|
||||
<t-tag v-if="!agent.is_builtin && agent.disabled_by_me" theme="default" size="small"
|
||||
class="disabled-badge">{{
|
||||
$t('agent.disabled') }}</t-tag>
|
||||
<t-tooltip
|
||||
:content="agent.config?.agent_mode === 'smart-reasoning' ? $t('agent.mode.agent') : $t('agent.mode.normal')"
|
||||
placement="top">
|
||||
<div class="feature-badge"
|
||||
:class="{ 'mode-normal': agent.config?.agent_mode === 'quick-answer', 'mode-agent': agent.config?.agent_mode === 'smart-reasoning' }">
|
||||
<t-icon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'"
|
||||
size="14px" />
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="agent.config?.web_search_enabled" :content="$t('agent.features.webSearch')"
|
||||
placement="top">
|
||||
<div class="feature-badge web-search">
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="8" cy="8" r="6" stroke="currentColor" stroke-width="1.2" fill="none" />
|
||||
<ellipse cx="8" cy="8" rx="2.5" ry="6" stroke="currentColor" stroke-width="1.2" fill="none" />
|
||||
<line x1="2" y1="6" x2="14" y2="6" stroke="currentColor" stroke-width="1.2" />
|
||||
<line x1="2" y1="10" x2="14" y2="10" stroke="currentColor" stroke-width="1.2" />
|
||||
</svg>
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="agent.config?.knowledge_bases?.length || agent.config?.kb_selection_mode === 'all'"
|
||||
:content="$t('agent.features.knowledgeBase')" placement="top">
|
||||
<div class="feature-badge knowledge">
|
||||
<t-icon name="folder" size="16px" />
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="agent.config?.mcp_services?.length || agent.config?.mcp_selection_mode === 'all'"
|
||||
:content="$t('agent.features.mcp')" placement="top">
|
||||
<div class="feature-badge mcp">
|
||||
<t-icon name="extension" size="16px" />
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="agent.config?.multi_turn_enabled" :content="$t('agent.features.multiTurn')"
|
||||
placement="top">
|
||||
<div class="feature-badge multi-turn">
|
||||
<t-icon name="chat-bubble" size="16px" />
|
||||
</div>
|
||||
</t-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 右下角:内置 / 来源徽章(我创建 / 同租户其他成员) -->
|
||||
<div v-if="agent.is_builtin" class="builtin-badge">
|
||||
<t-icon name="lock-on" size="12px" />
|
||||
<span>{{ $t('agent.builtin') }}</span>
|
||||
</div>
|
||||
<ResourceOriginBadge v-else :variant="agentOriginVariant(agent)"
|
||||
:creator-name="(agent as any).creator_name" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- 按空间筛选:该空间内全部智能体(含我共享的) -->
|
||||
<div v-if="spaceSelectionOrgId && spaceAgentsLoading" class="agent-list-main-loading">
|
||||
<t-loading size="medium" text="" />
|
||||
</div>
|
||||
<div v-else-if="spaceSelectionOrgId && spaceAgentsList.length > 0" class="agent-card-wrap">
|
||||
<div v-for="shared in spaceAgentsList" :key="'shared-' + shared.share_id" class="agent-card shared-agent-card"
|
||||
:class="{
|
||||
<div v-else-if="spaceSelectionOrgId && sortedSpaceAgentsList.length > 0" class="agent-card-wrap">
|
||||
<template v-for="(shared, index) in sortedSpaceAgentsList" :key="'shared-' + shared.share_id">
|
||||
<!-- 共享给我 · 可编辑:首次从 is_mine 进入共享 + editable -->
|
||||
<div v-if="showShareGroupHeaders
|
||||
&& !shared.is_mine
|
||||
&& isSharedAgentEditable(shared.permission)
|
||||
&& (index === 0 || sortedSpaceAgentsList[index - 1].is_mine)" class="agent-section-header">
|
||||
<span>{{ $t('agent.sections.sharedEditable') }}</span>
|
||||
</div>
|
||||
<!-- 共享给我 · 仅查看:首次从可编辑 / is_mine 进入 viewer -->
|
||||
<div v-if="showShareGroupHeaders
|
||||
&& !shared.is_mine
|
||||
&& !isSharedAgentEditable(shared.permission)
|
||||
&& (index === 0
|
||||
|| sortedSpaceAgentsList[index - 1].is_mine
|
||||
|| isSharedAgentEditable(sortedSpaceAgentsList[index - 1].permission))" class="agent-section-header">
|
||||
<span>{{ $t('agent.sections.sharedReadonly') }}</span>
|
||||
</div>
|
||||
<div 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="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">
|
||||
<path
|
||||
d="M10 3L10.8 6.2C10.9 6.7 11.3 7.1 11.8 7.2L15 8L11.8 8.8C11.3 8.9 10.9 9.3 10.8 9.8L10 13L9.2 9.8C9.1 9.3 8.7 8.9 8.2 8.8L5 8L8.2 7.2C8.7 7.1 9.1 6.7 9.2 6.2L10 3Z"
|
||||
stroke="currentColor" stroke-width="0.8" stroke-linecap="round" stroke-linejoin="round"
|
||||
fill="currentColor" fill-opacity="0.15" />
|
||||
</svg>
|
||||
<svg class="star-icon small" width="14" height="14" viewBox="0 0 20 20" fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M10 3L10.8 6.2C10.9 6.7 11.3 7.1 11.8 7.2L15 8L11.8 8.8C11.3 8.9 10.9 9.3 10.8 9.8L10 13L9.2 9.8C9.1 9.3 8.7 8.9 8.2 8.8L5 8L8.2 7.2C8.7 7.1 9.1 6.7 9.2 6.2L10 3Z"
|
||||
stroke="currentColor" stroke-width="0.8" stroke-linecap="round" stroke-linejoin="round"
|
||||
fill="currentColor" fill-opacity="0.15" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="card-header">
|
||||
<div class="card-header-left">
|
||||
<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 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">
|
||||
<path
|
||||
d="M10 3L10.8 6.2C10.9 6.7 11.3 7.1 11.8 7.2L15 8L11.8 8.8C11.3 8.9 10.9 9.3 10.8 9.8L10 13L9.2 9.8C9.1 9.3 8.7 8.9 8.2 8.8L5 8L8.2 7.2C8.7 7.1 9.1 6.7 9.2 6.2L10 3Z"
|
||||
stroke="currentColor" stroke-width="0.8" stroke-linecap="round" stroke-linejoin="round"
|
||||
fill="currentColor" fill-opacity="0.15" />
|
||||
</svg>
|
||||
<svg class="star-icon small" width="14" height="14" viewBox="0 0 20 20" fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M10 3L10.8 6.2C10.9 6.7 11.3 7.1 11.8 7.2L15 8L11.8 8.8C11.3 8.9 10.9 9.3 10.8 9.8L10 13L9.2 9.8C9.1 9.3 8.7 8.9 8.2 8.8L5 8L8.2 7.2C8.7 7.1 9.1 6.7 9.2 6.2L10 3Z"
|
||||
stroke="currentColor" stroke-width="0.8" stroke-linecap="round" stroke-linejoin="round"
|
||||
fill="currentColor" fill-opacity="0.15" />
|
||||
</svg>
|
||||
</div>
|
||||
<t-popup v-if="!shared.is_mine && authStore.hasRole('admin')"
|
||||
:visible="openMoreAgentId === 'shared-tab-' + shared.share_id" trigger="hover"
|
||||
overlayClassName="card-more-popup" destroy-on-close placement="bottom-right"
|
||||
@update:visible="(v: boolean) => { if (!v) openMoreAgentId = null }">
|
||||
<div class="more-wrap" :class="{ 'active-more': openMoreAgentId === 'shared-tab-' + shared.share_id }"
|
||||
@click.stop="toggleMore($event, 'shared-tab-' + shared.share_id)">
|
||||
<img class="more-icon" src="@/assets/img/more.png" alt="" />
|
||||
<div class="card-header">
|
||||
<div class="card-header-left">
|
||||
<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>
|
||||
<template #content>
|
||||
<div class="popup-menu">
|
||||
<div class="popup-menu-item" @click="handleToggleSharedDisabledFromShared(shared)">
|
||||
<t-icon class="menu-icon" name="poweroff" />
|
||||
<span>{{ shared.disabled_by_me ? $t('agent.enable') : $t('agent.disable') }}</span>
|
||||
</div>
|
||||
<t-popup v-if="!shared.is_mine && authStore.hasRole('admin')"
|
||||
:visible="openMoreAgentId === 'shared-tab-' + shared.share_id" trigger="hover"
|
||||
overlayClassName="card-more-popup" destroy-on-close placement="bottom-right"
|
||||
@update:visible="(v: boolean) => { if (!v) openMoreAgentId = null }">
|
||||
<div class="more-wrap" :class="{ 'active-more': openMoreAgentId === 'shared-tab-' + shared.share_id }"
|
||||
@click.stop="toggleMore($event, 'shared-tab-' + shared.share_id)">
|
||||
<img class="more-icon" src="@/assets/img/more.png" alt="" />
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="card-description">{{ shared.agent?.description || $t('agent.noDescription') }}</div>
|
||||
</div>
|
||||
<div class="card-bottom">
|
||||
<div class="bottom-left">
|
||||
<div class="feature-badges">
|
||||
<t-tag v-if="shared.disabled_by_me" theme="default" size="small" class="disabled-badge">{{
|
||||
$t('agent.disabled') }}</t-tag>
|
||||
<t-tooltip
|
||||
:content="shared.agent?.config?.agent_mode === 'smart-reasoning' ? $t('agent.mode.agent') : $t('agent.mode.normal')"
|
||||
placement="top">
|
||||
<div class="feature-badge"
|
||||
:class="{ 'mode-normal': shared.agent?.config?.agent_mode === 'quick-answer', 'mode-agent': shared.agent?.config?.agent_mode === 'smart-reasoning' }">
|
||||
<t-icon
|
||||
:name="shared.agent?.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'"
|
||||
size="14px" />
|
||||
<template #content>
|
||||
<div class="popup-menu">
|
||||
<div class="popup-menu-item" @click="handleToggleSharedDisabledFromShared(shared)">
|
||||
<t-icon class="menu-icon" name="poweroff" />
|
||||
<span>{{ shared.disabled_by_me ? $t('agent.enable') : $t('agent.disable') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="shared.agent?.config?.web_search_enabled" :content="$t('agent.features.webSearch')"
|
||||
placement="top">
|
||||
<div class="feature-badge web-search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="8" cy="8" r="6" stroke="currentColor" stroke-width="1.2" fill="none" />
|
||||
<ellipse cx="8" cy="8" rx="2.5" ry="6" stroke="currentColor" stroke-width="1.2" fill="none" />
|
||||
<line x1="2" y1="6" x2="14" y2="6" stroke="currentColor" stroke-width="1.2" />
|
||||
<line x1="2" y1="10" x2="14" y2="10" stroke="currentColor" stroke-width="1.2" />
|
||||
</svg></div>
|
||||
</t-tooltip>
|
||||
<t-tooltip
|
||||
v-if="shared.agent?.config?.knowledge_bases?.length || shared.agent?.config?.kb_selection_mode === 'all'"
|
||||
:content="$t('agent.features.knowledgeBase')" placement="top">
|
||||
<div class="feature-badge knowledge"><t-icon name="folder" size="16px" /></div>
|
||||
</t-tooltip>
|
||||
<t-tooltip
|
||||
v-if="shared.agent?.config?.mcp_services?.length || shared.agent?.config?.mcp_selection_mode === 'all'"
|
||||
:content="$t('agent.features.mcp')" placement="top">
|
||||
<div class="feature-badge mcp"><t-icon name="extension" size="16px" /></div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="shared.agent?.config?.multi_turn_enabled" :content="$t('agent.features.multiTurn')"
|
||||
placement="top">
|
||||
<div class="feature-badge multi-turn"><t-icon name="chat-bubble" size="16px" /></div>
|
||||
</t-tooltip>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="card-description">{{ shared.agent?.description || $t('agent.noDescription') }}</div>
|
||||
</div>
|
||||
<div class="card-bottom">
|
||||
<div class="bottom-left">
|
||||
<div class="feature-badges">
|
||||
<t-tag v-if="shared.disabled_by_me" theme="default" size="small" class="disabled-badge">{{
|
||||
$t('agent.disabled') }}</t-tag>
|
||||
<t-tooltip
|
||||
:content="shared.agent?.config?.agent_mode === 'smart-reasoning' ? $t('agent.mode.agent') : $t('agent.mode.normal')"
|
||||
placement="top">
|
||||
<div class="feature-badge"
|
||||
:class="{ 'mode-normal': shared.agent?.config?.agent_mode === 'quick-answer', 'mode-agent': shared.agent?.config?.agent_mode === 'smart-reasoning' }">
|
||||
<t-icon
|
||||
:name="shared.agent?.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'"
|
||||
size="14px" />
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="shared.agent?.config?.web_search_enabled" :content="$t('agent.features.webSearch')"
|
||||
placement="top">
|
||||
<div class="feature-badge web-search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="8" cy="8" r="6" stroke="currentColor" stroke-width="1.2" fill="none" />
|
||||
<ellipse cx="8" cy="8" rx="2.5" ry="6" stroke="currentColor" stroke-width="1.2" fill="none" />
|
||||
<line x1="2" y1="6" x2="14" y2="6" stroke="currentColor" stroke-width="1.2" />
|
||||
<line x1="2" y1="10" x2="14" y2="10" stroke="currentColor" stroke-width="1.2" />
|
||||
</svg></div>
|
||||
</t-tooltip>
|
||||
<t-tooltip
|
||||
v-if="shared.agent?.config?.knowledge_bases?.length || shared.agent?.config?.kb_selection_mode === 'all'"
|
||||
:content="$t('agent.features.knowledgeBase')" placement="top">
|
||||
<div class="feature-badge knowledge"><t-icon name="folder" size="16px" /></div>
|
||||
</t-tooltip>
|
||||
<t-tooltip
|
||||
v-if="shared.agent?.config?.mcp_services?.length || shared.agent?.config?.mcp_selection_mode === 'all'"
|
||||
:content="$t('agent.features.mcp')" placement="top">
|
||||
<div class="feature-badge mcp"><t-icon name="extension" size="16px" /></div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="shared.agent?.config?.multi_turn_enabled" :content="$t('agent.features.multiTurn')"
|
||||
placement="top">
|
||||
<div class="feature-badge multi-turn"><t-icon name="chat-bubble" size="16px" /></div>
|
||||
</t-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 右下角:空间图标+名称 -->
|
||||
<div class="card-bottom-source">
|
||||
<img src="@/assets/img/organization-green.svg" class="org-icon" alt="" aria-hidden="true" />
|
||||
<span class="org-source-text">{{ shared.org_name }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 右下角:空间图标+名称 -->
|
||||
<div class="card-bottom-source">
|
||||
<img src="@/assets/img/organization-green.svg" class="org-icon" alt="" aria-hidden="true" />
|
||||
<span class="org-source-text">{{ shared.org_name }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- 空状态:全部(保留创建 CTA) -->
|
||||
@@ -649,6 +704,7 @@ import type { SharedAgentInfo, OrganizationSharedAgentItem } from '@/api/organiz
|
||||
import AgentEditorModal from './AgentEditorModal.vue'
|
||||
import AgentAvatar from '@/components/AgentAvatar.vue'
|
||||
import ListSpaceSidebar from '@/components/ListSpaceSidebar.vue'
|
||||
import ResourceOriginBadge from '@/components/ResourceOriginBadge.vue'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { useListUrlState } from '@/composables/useListUrlState'
|
||||
import { useResourcePins } from '@/composables/useResourcePins'
|
||||
@@ -665,8 +721,10 @@ interface AgentWithUI extends CustomAgent {
|
||||
disabled_by_me?: boolean
|
||||
}
|
||||
|
||||
/** 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 })
|
||||
/** Merged agent for "all" tab: my agents (isMine: true) or shared
|
||||
* (isMine: false, org_name, source_tenant_id, share_id, permission, disabled_by_me?).
|
||||
* `permission` drives the「可编辑 / 仅查看」分组,仅在 shared 分支携带。 */
|
||||
type DisplayAgent = (AgentWithUI & { isMine: true }) | (CustomAgent & { isMine: false; org_name: string; source_tenant_id: number; share_id: string; permission?: string; showMore?: boolean; disabled_by_me?: boolean })
|
||||
|
||||
// 左侧空间选择:默认根据当前角色决定。
|
||||
// 与 KnowledgeBaseList 同款逻辑:Viewer 在当前租户里通常没有自建智能体,
|
||||
@@ -795,8 +853,27 @@ const filteredAgents = computed<DisplayAgent[]>(() => {
|
||||
}
|
||||
if (spaceSelection.value !== 'all') return []
|
||||
const list: DisplayAgent[] = []
|
||||
agents.value.forEach(a => list.push({ ...a, isMine: true as const }))
|
||||
sharedAgents.value.forEach(shared => {
|
||||
// 本租户内的 agent 拆成「我创建」与「同事创建」两段,让 contributor
|
||||
// 视图能在二者之间插入「本空间 · 仅查看」分组标题。内建 agent
|
||||
// (is_builtin=true, created_by="") 视作"非我"——它本来就是租户共有的,
|
||||
// 也归到只读那一档;如果不是 contributor,标题被开关压住,看起来无差别。
|
||||
const ownMine: AgentWithUI[] = []
|
||||
const teammateMine: AgentWithUI[] = []
|
||||
agents.value.forEach(a => {
|
||||
if (isMyAgent(a)) ownMine.push(a)
|
||||
else teammateMine.push(a)
|
||||
})
|
||||
ownMine.forEach(a => list.push({ ...a, isMine: true as const }))
|
||||
teammateMine.forEach(a => list.push({ ...a, isMine: true as const }))
|
||||
// 共享区按 share permission 排序:editor/admin 在前,viewer 在后,
|
||||
// 让「共享给我 · 可编辑 / 仅查看」分组标题正好落在过渡处。即便当前角色
|
||||
// 不显示分组标题,排序也保留——展示更可预测。
|
||||
const sortedShared = [...sharedAgents.value].sort((a, b) => {
|
||||
const aE = isSharedAgentEditable(a.permission) ? 0 : 1
|
||||
const bE = isSharedAgentEditable(b.permission) ? 0 : 1
|
||||
return aE - bE
|
||||
})
|
||||
sortedShared.forEach(shared => {
|
||||
if (!shared.agent) return
|
||||
list.push({
|
||||
...shared.agent,
|
||||
@@ -804,12 +881,37 @@ const filteredAgents = computed<DisplayAgent[]>(() => {
|
||||
org_name: shared.org_name,
|
||||
source_tenant_id: shared.source_tenant_id,
|
||||
share_id: shared.share_id,
|
||||
permission: shared.permission,
|
||||
disabled_by_me: shared.disabled_by_me,
|
||||
showMore: false
|
||||
} as DisplayAgent)
|
||||
})
|
||||
return list
|
||||
})
|
||||
|
||||
// 「工作空间」视图下的稳定排序:本租户内「我创建」在前、「同事创建 / 内建」
|
||||
// 在后。给 contributor 视图把「本空间 · 仅查看」分组标题正好插在过渡处。
|
||||
const sortedMineAgents = computed(() => {
|
||||
const own: AgentWithUI[] = []
|
||||
const teammate: AgentWithUI[] = []
|
||||
agents.value.forEach(a => {
|
||||
if (isMyAgent(a)) own.push(a)
|
||||
else teammate.push(a)
|
||||
})
|
||||
return [...own, ...teammate]
|
||||
})
|
||||
|
||||
// 空间视角下的稳定排序:我自己创建的(is_mine)放前面,其余按 permission 切分。
|
||||
const sortedSpaceAgentsList = computed(() => {
|
||||
return [...spaceAgentsList.value].sort((a, b) => {
|
||||
const aMine = a.is_mine ? 0 : 1
|
||||
const bMine = b.is_mine ? 0 : 1
|
||||
if (aMine !== bMine) return aMine - bMine
|
||||
const aE = isSharedAgentEditable(a.permission) ? 0 : 1
|
||||
const bE = isSharedAgentEditable(b.permission) ? 0 : 1
|
||||
return aE - bE
|
||||
})
|
||||
})
|
||||
const loading = ref(false)
|
||||
const deleteVisible = ref(false)
|
||||
const deletingAgent = ref<AgentWithUI | null>(null)
|
||||
@@ -1042,6 +1144,32 @@ function canManageAgent(agent: AgentWithUI): boolean {
|
||||
return authStore.hasRole('admin')
|
||||
}
|
||||
|
||||
// isMyAgent 仅用于卡片来源徽章在「我创建」与「同租户其他成员创建」之间切换。
|
||||
// 跟 canManageAgent 区别:管理权限有 admin 兜底;徽章纯粹按 created_by 匹配。
|
||||
// 内建 agent(created_by="")也归到非 mine 一档,由模板上的 builtin 分支
|
||||
// 提前拦截,不会落到 ResourceOriginBadge。
|
||||
function isMyAgent(agent: { created_by?: string }): boolean {
|
||||
const userId = authStore.user?.id || ''
|
||||
return !!(agent.created_by && userId && agent.created_by === userId)
|
||||
}
|
||||
|
||||
// agentOriginVariant 跟 kbOriginVariant 对齐:右下角徽章不再重复租户名
|
||||
// (顶部 TenantSelector 已经标了租户身份),所有角色都用 creator 变体。
|
||||
// 内建 agent 走 v-else 前的 builtin 分支,到不了这里。
|
||||
function agentOriginVariant(agent: { created_by?: string }): 'mine' | 'creator' {
|
||||
return isMyAgent(agent) ? 'mine' : 'creator'
|
||||
}
|
||||
|
||||
// 共享 agent 的可编辑/只读分组开关,与 KB 列表逻辑保持一致:仅对
|
||||
// contributor / editor 中间档展示分组标题。Viewer / Admin+ 不分组。
|
||||
const AGENT_EDITABLE_PERMS = new Set(['admin', 'editor'])
|
||||
function isSharedAgentEditable(perm: string | undefined): boolean {
|
||||
return !!perm && AGENT_EDITABLE_PERMS.has(perm)
|
||||
}
|
||||
const showShareGroupHeaders = computed(() => {
|
||||
return authStore.hasRole('contributor') && !authStore.hasRole('admin')
|
||||
})
|
||||
|
||||
const handleDelete = (agent: AgentWithUI) => {
|
||||
openMoreAgentId.value = null
|
||||
deletingAgent.value = agent
|
||||
@@ -1417,6 +1545,20 @@ defineExpose({
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
// 共享给我 · 可编辑 / 仅查看 分组标题,与 KB 列表 .kb-section-header 对齐。
|
||||
.agent-section-header {
|
||||
grid-column: 1 / -1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 2px 0;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-family: var(--app-font-family);
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
|
||||
@keyframes contentFadeIn {
|
||||
from {
|
||||
|
||||
@@ -102,13 +102,45 @@
|
||||
</div>
|
||||
<!-- 全部:我的知识库 + 共享给我的知识库 -->
|
||||
<template v-for="(kb, index) in filteredKnowledgeBases" :key="kb.id">
|
||||
<!-- 「其他」分组标题:从置顶过渡到非置顶时插入 -->
|
||||
<!-- 「其他」(置顶→非置顶):admin/owner/viewer 维持原行为,
|
||||
在任意 mine 子段内的置顶→非置顶处触发;contributor 视图下
|
||||
跨创建者的边界由下面更语义化的分组标题接管,「其他」收紧到
|
||||
同一创建者子段内部,以免双标题叠加。 -->
|
||||
<div v-if="index > 0
|
||||
&& filteredKnowledgeBases[index - 1].isMine
|
||||
&& filteredKnowledgeBases[index - 1].is_pinned
|
||||
&& !(kb.isMine && kb.is_pinned)" class="kb-section-header">
|
||||
&& kb.isMine
|
||||
&& !kb.is_pinned
|
||||
&& (!showShareGroupHeaders
|
||||
|| isMyKb(filteredKnowledgeBases[index - 1] as KB) === isMyKb(kb as KB))" class="kb-section-header">
|
||||
<span>{{ $t('knowledgeList.sections.others') }}</span>
|
||||
</div>
|
||||
<!-- 本空间 · 仅查看:本租户里同事创建、对当前 contributor 不可编辑 -->
|
||||
<div v-if="showShareGroupHeaders
|
||||
&& kb.isMine
|
||||
&& !isMyKb(kb as KB)
|
||||
&& (index === 0
|
||||
|| !filteredKnowledgeBases[index - 1].isMine
|
||||
|| isMyKb(filteredKnowledgeBases[index - 1] as KB))" class="kb-section-header">
|
||||
<span>{{ $t('knowledgeList.sections.tenantReadonly') }}</span>
|
||||
</div>
|
||||
<!-- 共享给我 · 可编辑:从「我的(含同事)」首次过渡到共享 + 可编辑 -->
|
||||
<div v-if="showShareGroupHeaders
|
||||
&& !kb.isMine
|
||||
&& isSharedKbEditable((kb as any).permission)
|
||||
&& (index === 0 || filteredKnowledgeBases[index - 1].isMine)" class="kb-section-header">
|
||||
<span>{{ $t('knowledgeList.sections.sharedEditable') }}</span>
|
||||
</div>
|
||||
<!-- 共享给我 · 仅查看:从「可编辑共享 / 我的」过渡到 viewer 共享 -->
|
||||
<div v-if="showShareGroupHeaders
|
||||
&& !kb.isMine
|
||||
&& !isSharedKbEditable((kb as any).permission)
|
||||
&& (index === 0
|
||||
|| filteredKnowledgeBases[index - 1].isMine
|
||||
|| isSharedKbEditable((filteredKnowledgeBases[index - 1] as any).permission))"
|
||||
class="kb-section-header">
|
||||
<span>{{ $t('knowledgeList.sections.sharedReadonly') }}</span>
|
||||
</div>
|
||||
<!-- 我的知识库卡片 -->
|
||||
<div v-if="kb.isMine" class="kb-card" :class="{
|
||||
'uninitialized': !isInitialized(kb),
|
||||
@@ -203,10 +235,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!authStore.isLiteMode" class="bottom-right">
|
||||
<div class="personal-source">
|
||||
<t-icon name="user" size="14px" />
|
||||
<span>{{ $t('knowledgeList.myLabel') }}</span>
|
||||
</div>
|
||||
<ResourceOriginBadge :variant="kbOriginVariant(kb)" :creator-name="kb.creator_name" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -251,7 +280,7 @@
|
||||
<t-icon :name="kb.type === 'faq' ? 'chat-bubble-help' : 'folder'" size="14px" />
|
||||
<span class="badge-count">{{ kb.type === 'faq' ? (kb.chunk_count || '-') : (kb.knowledge_count
|
||||
|| '-')
|
||||
}}</span>
|
||||
}}</span>
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<t-tooltip v-if="kb.extract_config?.enabled" :content="$t('knowledgeList.features.knowledgeGraph')"
|
||||
@@ -289,18 +318,30 @@
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div v-if="spaceSelection === 'mine' && kbs.length > 0" class="kb-card-wrap">
|
||||
<div v-if="spaceSelection === 'mine' && sortedMineKbs.length > 0" class="kb-card-wrap">
|
||||
<!-- 置顶分组标题 -->
|
||||
<div v-if="kbs[0] && kbs[0].is_pinned" class="kb-section-header kb-section-header-pinned">
|
||||
<div v-if="sortedMineKbs[0] && sortedMineKbs[0].is_pinned" class="kb-section-header kb-section-header-pinned">
|
||||
<t-icon name="pin-filled" size="14px" />
|
||||
<span>{{ $t('knowledgeList.sections.pinned') }}</span>
|
||||
</div>
|
||||
<!-- 我的知识库 -->
|
||||
<template v-for="(kb, index) in kbs" :key="kb.id">
|
||||
<!-- 「其他」分组标题:从置顶过渡到非置顶时插入 -->
|
||||
<div v-if="index > 0 && kbs[index - 1].is_pinned && !kb.is_pinned" class="kb-section-header">
|
||||
<template v-for="(kb, index) in sortedMineKbs" :key="kb.id">
|
||||
<!-- 「其他」(置顶→非置顶):admin/owner/viewer 保留原行为;
|
||||
contributor 收紧到同一创建者子段内部,跨创建者边界让位给
|
||||
「本空间 · 仅查看」标题。 -->
|
||||
<div v-if="index > 0
|
||||
&& sortedMineKbs[index - 1].is_pinned
|
||||
&& !kb.is_pinned
|
||||
&& (!showShareGroupHeaders
|
||||
|| isMyKb(sortedMineKbs[index - 1]) === isMyKb(kb))" class="kb-section-header">
|
||||
<span>{{ $t('knowledgeList.sections.others') }}</span>
|
||||
</div>
|
||||
<!-- 本空间 · 仅查看:从「我创建」首次过渡到「同事创建」 -->
|
||||
<div v-if="showShareGroupHeaders
|
||||
&& !isMyKb(kb)
|
||||
&& (index === 0 || isMyKb(sortedMineKbs[index - 1]))" class="kb-section-header">
|
||||
<span>{{ $t('knowledgeList.sections.tenantReadonly') }}</span>
|
||||
</div>
|
||||
<div class="kb-card" :class="{
|
||||
'uninitialized': !isInitialized(kb),
|
||||
'kb-type-document': (kb.type || 'document') === 'document',
|
||||
@@ -397,10 +438,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!authStore.isLiteMode" class="bottom-right">
|
||||
<div class="personal-source">
|
||||
<t-icon name="user" size="14px" />
|
||||
<span>{{ $t('knowledgeList.myLabel') }}</span>
|
||||
</div>
|
||||
<ResourceOriginBadge :variant="kbOriginVariant(kb)" :creator-name="kb.creator_name" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -413,62 +451,80 @@
|
||||
<div v-if="spaceSelectionOrgId && spaceKbsLoading" class="kb-list-main-loading">
|
||||
<t-loading size="medium" text="" />
|
||||
</div>
|
||||
<div v-else-if="spaceSelectionOrgId && spaceKbsList.length > 0" class="kb-card-wrap">
|
||||
<div 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="{
|
||||
<div v-else-if="spaceSelectionOrgId && sortedSpaceKbsList.length > 0" class="kb-card-wrap">
|
||||
<template v-for="(shared, index) in sortedSpaceKbsList"
|
||||
:key="'shared-' + (shared.share_id || `agent-${shared.knowledge_base?.id}-${shared.source_from_agent?.agent_id || ''}`)">
|
||||
<!-- 共享给我 · 可编辑:从「我的」首次进入「共享 + 可编辑」 -->
|
||||
<div v-if="showShareGroupHeaders
|
||||
&& !shared.is_mine
|
||||
&& isSharedKbEditable(shared.permission)
|
||||
&& (index === 0 || sortedSpaceKbsList[index - 1].is_mine)" class="kb-section-header">
|
||||
<span>{{ $t('knowledgeList.sections.sharedEditable') }}</span>
|
||||
</div>
|
||||
<!-- 共享给我 · 仅查看:从「可编辑共享 / 我的」首次进入「viewer」 -->
|
||||
<div v-if="showShareGroupHeaders
|
||||
&& !shared.is_mine
|
||||
&& !isSharedKbEditable(shared.permission)
|
||||
&& (index === 0
|
||||
|| sortedSpaceKbsList[index - 1].is_mine
|
||||
|| isSharedKbEditable(sortedSpaceKbsList[index - 1].permission))" class="kb-section-header">
|
||||
<span>{{ $t('knowledgeList.sections.sharedReadonly') }}</span>
|
||||
</div>
|
||||
<div 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="handleSharedKbClick(shared)">
|
||||
<!-- 卡片头部 -->
|
||||
<div class="card-header">
|
||||
<span class="card-title" :title="shared.knowledge_base.name">{{ shared.knowledge_base.name }}</span>
|
||||
<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>
|
||||
</t-tooltip>
|
||||
</div>
|
||||
|
||||
<!-- 卡片内容 -->
|
||||
<div class="card-content">
|
||||
<div class="card-description">
|
||||
{{ shared.knowledge_base.description || $t('knowledgeBase.noDescription') }}
|
||||
<!-- 卡片头部 -->
|
||||
<div class="card-header">
|
||||
<span class="card-title" :title="shared.knowledge_base.name">{{ shared.knowledge_base.name }}</span>
|
||||
<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>
|
||||
</t-tooltip>
|
||||
</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 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 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>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- 全部空状态:保留「新建知识库」CTA,因为是租户没有任何 KB 的真空场景 -->
|
||||
@@ -534,7 +590,7 @@
|
||||
<div class="circle-btn">
|
||||
<span class="circle-btn-txt" @click="deleteVisible = false">{{ $t('common.cancel') }}</span>
|
||||
<span class="circle-btn-txt confirm" @click="confirmDelete">{{ $t('knowledgeList.delete.confirmButton')
|
||||
}}</span>
|
||||
}}</span>
|
||||
</div>
|
||||
</div>
|
||||
</t-dialog>
|
||||
@@ -593,7 +649,7 @@
|
||||
<div class="shared-detail-row">
|
||||
<span class="shared-detail-label">{{ $t('knowledgeList.detail.sharedAt') }}</span>
|
||||
<span class="shared-detail-value">{{ formatStringDate(new Date(currentSharedKbForDetail.shared_at))
|
||||
}}</span>
|
||||
}}</span>
|
||||
</div>
|
||||
<div class="shared-detail-row">
|
||||
<span class="shared-detail-label">{{ $t('knowledgeList.detail.myPermission') }}</span>
|
||||
@@ -605,7 +661,7 @@
|
||||
</div>
|
||||
<div class="shared-detail-drawer-footer">
|
||||
<t-button theme="default" variant="outline" @click="closeSharedDetailPanel">{{ $t('common.close')
|
||||
}}</t-button>
|
||||
}}</t-button>
|
||||
<t-button theme="primary" class="go-to-kb-btn" @click="goToSharedKbFromPanel">
|
||||
<t-icon name="browse" />
|
||||
{{ $t('knowledgeList.detail.goToKb') }}
|
||||
@@ -632,6 +688,7 @@ import { listOrganizationSharedKnowledgeBases, type SharedKnowledgeBase, type Or
|
||||
import KnowledgeBaseEditorModal from './KnowledgeBaseEditorModal.vue'
|
||||
import ShareKnowledgeBaseDialog from '@/components/ShareKnowledgeBaseDialog.vue'
|
||||
import ListSpaceSidebar from '@/components/ListSpaceSidebar.vue'
|
||||
import ResourceOriginBadge from '@/components/ResourceOriginBadge.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useListUrlState } from '@/composables/useListUrlState'
|
||||
import { useResourcePins } from '@/composables/useResourcePins'
|
||||
@@ -693,6 +750,8 @@ interface KB {
|
||||
// gating the per-card more-menu (Settings / Delete). Empty for legacy
|
||||
// KBs created before PR 5; those fall back to the role gate.
|
||||
creator_id?: string;
|
||||
// creator_name 由后端 list 接口回填,仅用于卡片右下角来源徽章的 tooltip。
|
||||
creator_name?: string;
|
||||
}
|
||||
|
||||
const kbs = ref<KB[]>([])
|
||||
@@ -741,6 +800,32 @@ const sharedKbsByOrg = computed(() => {
|
||||
// 空间视角:该空间内全部知识库(含我共享的),选中空间时请求新接口
|
||||
const spaceKbsList = ref<OrganizationSharedKnowledgeBaseItem[]>([])
|
||||
const spaceKbsLoading = ref(false)
|
||||
|
||||
// 「工作空间」视图下的稳定排序:本租户内「我创建」在前、「同事创建」在后;
|
||||
// 子段内保留服务端的置顶优先顺序。给 contributor 视图把「本空间 · 仅查看」
|
||||
// 分组标题正好插在过渡处;其他角色看不到标题,纯排序变化也无害。
|
||||
const sortedMineKbs = computed(() => {
|
||||
const own: KB[] = []
|
||||
const teammate: KB[] = []
|
||||
kbs.value.forEach(kb => {
|
||||
if (isMyKb(kb)) own.push(kb)
|
||||
else teammate.push(kb)
|
||||
})
|
||||
return [...own, ...teammate]
|
||||
})
|
||||
|
||||
// 空间视角下的稳定排序:我创建的(is_mine)放在前面,剩下的共享部分再按
|
||||
// 可编辑 / 仅查看 排序——这样空间列表跟「全部」视图的视觉顺序一致。
|
||||
const sortedSpaceKbsList = computed(() => {
|
||||
return [...spaceKbsList.value].sort((a, b) => {
|
||||
const aMine = a.is_mine ? 0 : 1
|
||||
const bMine = b.is_mine ? 0 : 1
|
||||
if (aMine !== bMine) return aMine - bMine
|
||||
const aE = isSharedKbEditable(a.permission) ? 0 : 1
|
||||
const bE = isSharedKbEditable(b.permission) ? 0 : 1
|
||||
return aE - bE
|
||||
})
|
||||
})
|
||||
const spaceCountByOrg = ref<Record<string, number>>({})
|
||||
|
||||
// 各空间下的共享知识库数量(用于侧栏展示):优先用接口返回的该空间总数,否则用「共享给我」数量
|
||||
@@ -834,6 +919,22 @@ const recentsList = computed(() => {
|
||||
.filter((x): x is NonNullable<typeof x> => x !== null)
|
||||
})
|
||||
|
||||
// 可编辑权限:editor / admin。viewer 进入「仅查看」组。
|
||||
// 用 share-level permission(不是租户角色)做判断——跨租户拿到 viewer 的,
|
||||
// 即便我在本租户是 owner 也确实改不动那个 KB;反过来跨租户拿到 editor 的,
|
||||
// 哪怕我在本租户是 contributor 也确实能改。
|
||||
const EDITABLE_PERMS = new Set(['admin', 'editor'])
|
||||
function isSharedKbEditable(perm: string | undefined): boolean {
|
||||
return !!perm && EDITABLE_PERMS.has(perm)
|
||||
}
|
||||
|
||||
// 是否在共享区展示「可编辑 / 仅查看」二级分组:仅对中间档(contributor / editor)
|
||||
// 有意义。viewer 反正都是只读,admin / owner 视角统一管理,分组反而碎。
|
||||
// 这里只是 UI 呈现,权限由后端兜底,不要把它当成安全边界。
|
||||
const showShareGroupHeaders = computed(() => {
|
||||
return authStore.hasRole('contributor') && !authStore.hasRole('admin')
|
||||
})
|
||||
|
||||
// Filtered knowledge bases: 全部 = 我的 + 全部共享;我的 = 仅我的
|
||||
//
|
||||
// Favorites / Recents reuse the same render path as `all` — they're just
|
||||
@@ -854,10 +955,26 @@ const filteredKnowledgeBases = computed(() => {
|
||||
return []
|
||||
}
|
||||
const result: Array<(KB & { isMine: true }) | (SharedKnowledgeBase['knowledge_base'] & { isMine: false; permission: string; shared_at: string; share_id: string } & any)> = []
|
||||
// 本租户的 KB 拆成「我创建」与「同事创建」两段,让 contributor 视图能在
|
||||
// 二者之间插入「本空间 · 仅查看」分组标题。子段内部仍按 server 返回的
|
||||
// 顺序(置顶在前),所以 pinned/others 那条 mine→mine 的次级分组依然成立。
|
||||
const ownMine: KB[] = []
|
||||
const teammateMine: KB[] = []
|
||||
kbs.value.forEach(kb => {
|
||||
result.push({ ...kb, isMine: true as const })
|
||||
if (isMyKb(kb)) ownMine.push(kb)
|
||||
else teammateMine.push(kb)
|
||||
})
|
||||
sharedKbs.value.forEach(shared => {
|
||||
ownMine.forEach(kb => result.push({ ...kb, isMine: true as const }))
|
||||
teammateMine.forEach(kb => result.push({ ...kb, isMine: true as const }))
|
||||
// 共享区按 permission 排序:可编辑(admin/editor)在前,仅查看(viewer)在后。
|
||||
// 即便当前角色不显示分组标题,排序也保留——展示更可预测,并且让分组开关切换
|
||||
// 时不会引起卡片顺序跳变。
|
||||
const sortedShared = [...sharedKbs.value].sort((a, b) => {
|
||||
const aE = isSharedKbEditable(a.permission) ? 0 : 1
|
||||
const bE = isSharedKbEditable(b.permission) ? 0 : 1
|
||||
return aE - bE
|
||||
})
|
||||
sortedShared.forEach(shared => {
|
||||
const kb = shared.knowledge_base
|
||||
if (!kb) return
|
||||
result.push({
|
||||
@@ -1030,6 +1147,26 @@ function canManageKBCard(kb: KB): boolean {
|
||||
return authStore.hasRole('admin')
|
||||
}
|
||||
|
||||
// isMyKb 仅用于卡片右下角徽章在「我创建」与「同租户其他成员创建」之间切换。
|
||||
// 与 canManageKBCard 不同:管理权限有 admin 兜底,徽章纯粹按创建者匹配。
|
||||
// creator_id 为空(PR 5 RBAC 迁移之前的老 KB)一律按 tenant 处理——避免把
|
||||
// 全租户共有的旧 KB 错误地都标成「我创建」。
|
||||
function isMyKb(kb: { creator_id?: string }): boolean {
|
||||
const userId = authStore.user?.id || ''
|
||||
return !!(kb.creator_id && userId && kb.creator_id === userId)
|
||||
}
|
||||
|
||||
// kbOriginVariant 决定卡片右下角徽章的展示形态:
|
||||
// - 我自己创建的:mine(绿色 "我创建")
|
||||
// - 同租户他人创建的:creator 变体——只显示创建者名字。用户始终在
|
||||
// 某个工作空间内浏览(顶部 TenantSelector 已经标了租户身份),右下
|
||||
// 角再贴一遍租户名属于重复信息;contributor / admin / owner / viewer
|
||||
// 看到的徽章一致。创建者无法解析时,creator 变体自动回退到
|
||||
// resourceOrigin.tenant 文案("本空间"),不会出现空标签。
|
||||
function kbOriginVariant(kb: { creator_id?: string }): 'mine' | 'creator' {
|
||||
return isMyKb(kb) ? 'mine' : 'creator'
|
||||
}
|
||||
|
||||
// 通过 ID 处理设置(用于全部 Tab 下的知识库)
|
||||
const handleSettingsById = (id: string) => {
|
||||
goSettings(id)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -16,15 +17,23 @@ import (
|
||||
|
||||
// CustomAgentHandler defines the HTTP handler for custom agent operations
|
||||
type CustomAgentHandler struct {
|
||||
service interfaces.CustomAgentService
|
||||
service interfaces.CustomAgentService
|
||||
disabledRepo interfaces.TenantDisabledSharedAgentRepository
|
||||
// userService 仅用于 list 接口批量回填 creator_name,作用见
|
||||
// KnowledgeBaseHandler.userService。
|
||||
userService interfaces.UserService
|
||||
}
|
||||
|
||||
// NewCustomAgentHandler creates a new custom agent handler instance
|
||||
func NewCustomAgentHandler(service interfaces.CustomAgentService, disabledRepo interfaces.TenantDisabledSharedAgentRepository) *CustomAgentHandler {
|
||||
func NewCustomAgentHandler(
|
||||
service interfaces.CustomAgentService,
|
||||
disabledRepo interfaces.TenantDisabledSharedAgentRepository,
|
||||
userService interfaces.UserService,
|
||||
) *CustomAgentHandler {
|
||||
return &CustomAgentHandler{
|
||||
service: service,
|
||||
service: service,
|
||||
disabledRepo: disabledRepo,
|
||||
userService: userService,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,6 +224,11 @@ func (h *CustomAgentHandler) ListAgents(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 批量回填 creator_name,作用同 KB 列表:让前端能区分「我创建」与「同租户其他成员」。
|
||||
// 内建 agent(IsBuiltin=true, CreatedBy="")不会有 creator_name,前端按 builtin
|
||||
// 分支单独渲染。
|
||||
enrichAgentCreatorNames(ctx, h.userService, agents)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"data": agents,
|
||||
@@ -222,6 +236,43 @@ func (h *CustomAgentHandler) ListAgents(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// enrichAgentCreatorNames 批量把 agent.CreatedBy 解析成展示名。失败吞掉,
|
||||
// 不影响列表本身可用。与 enrichKBCreatorNames 行为对齐。
|
||||
func enrichAgentCreatorNames(ctx context.Context, userSvc interfaces.UserService, agents []*types.CustomAgent) {
|
||||
if userSvc == nil || len(agents) == 0 {
|
||||
return
|
||||
}
|
||||
idSet := make(map[string]struct{}, len(agents))
|
||||
for _, ag := range agents {
|
||||
if ag.IsBuiltin || ag.CreatedBy == "" {
|
||||
continue
|
||||
}
|
||||
idSet[ag.CreatedBy] = struct{}{}
|
||||
}
|
||||
if len(idSet) == 0 {
|
||||
return
|
||||
}
|
||||
ids := make([]string, 0, len(idSet))
|
||||
for id := range idSet {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
users, err := userSvc.GetUsersByIDs(ctx, ids)
|
||||
if err != nil {
|
||||
logger.Warnf(ctx, "Failed to resolve agent creator names: %v", err)
|
||||
return
|
||||
}
|
||||
for _, ag := range agents {
|
||||
if ag.IsBuiltin || ag.CreatedBy == "" {
|
||||
continue
|
||||
}
|
||||
u, ok := users[ag.CreatedBy]
|
||||
if !ok || u == nil {
|
||||
continue
|
||||
}
|
||||
ag.CreatorName = pickUserDisplayName(u)
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateAgent godoc
|
||||
// @Summary 更新智能体
|
||||
// @Description 更新智能体的名称、描述和配置
|
||||
|
||||
@@ -32,6 +32,9 @@ type KnowledgeBaseHandler struct {
|
||||
agentShareService interfaces.AgentShareService
|
||||
asynqClient interfaces.TaskEnqueuer
|
||||
vectorStoreService interfaces.VectorStoreService // enriches KB responses with bound store display
|
||||
// userService 仅在 list 类接口里用于批量回填 creator_name;
|
||||
// 真正的鉴权由 RBAC 中间件 + Lookup 完成,这里不参与决策。
|
||||
userService interfaces.UserService
|
||||
}
|
||||
|
||||
// NewKnowledgeBaseHandler creates a new knowledge base handler instance
|
||||
@@ -42,6 +45,7 @@ func NewKnowledgeBaseHandler(
|
||||
agentShareService interfaces.AgentShareService,
|
||||
asynqClient interfaces.TaskEnqueuer,
|
||||
vectorStoreService interfaces.VectorStoreService,
|
||||
userService interfaces.UserService,
|
||||
) *KnowledgeBaseHandler {
|
||||
return &KnowledgeBaseHandler{
|
||||
service: service,
|
||||
@@ -50,6 +54,7 @@ func NewKnowledgeBaseHandler(
|
||||
agentShareService: agentShareService,
|
||||
asynqClient: asynqClient,
|
||||
vectorStoreService: vectorStoreService,
|
||||
userService: userService,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -548,12 +553,67 @@ func (h *KnowledgeBaseHandler) ListKnowledgeBases(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// 批量回填 creator_name,让前端列表能区分「我创建」与「同租户其他成员创建」。
|
||||
// 仅在 list 接口里回填,详情 / 编辑场景不依赖这个字段;解析失败(用户已删除、
|
||||
// CreatorID 为空的老数据)就让字段为空,前端按 fallback 渲染。
|
||||
enrichKBCreatorNames(ctx, h.userService, kbs)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"data": kbs,
|
||||
})
|
||||
}
|
||||
|
||||
// enrichKBCreatorNames 把 KB 列表里的 CreatorID 批量解析成展示名(username
|
||||
// 优先,退化到 email)。任意一步失败都吞掉错误:creator_name 缺失只会影响
|
||||
// 卡片右下角的徽章展示,不该影响列表本身可用。
|
||||
func enrichKBCreatorNames(ctx context.Context, userSvc interfaces.UserService, kbs []*types.KnowledgeBase) {
|
||||
if userSvc == nil || len(kbs) == 0 {
|
||||
return
|
||||
}
|
||||
idSet := make(map[string]struct{}, len(kbs))
|
||||
for _, kb := range kbs {
|
||||
if kb.CreatorID != "" {
|
||||
idSet[kb.CreatorID] = struct{}{}
|
||||
}
|
||||
}
|
||||
if len(idSet) == 0 {
|
||||
return
|
||||
}
|
||||
ids := make([]string, 0, len(idSet))
|
||||
for id := range idSet {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
users, err := userSvc.GetUsersByIDs(ctx, ids)
|
||||
if err != nil {
|
||||
logger.Warnf(ctx, "Failed to resolve KB creator names: %v", err)
|
||||
return
|
||||
}
|
||||
for _, kb := range kbs {
|
||||
if kb.CreatorID == "" {
|
||||
continue
|
||||
}
|
||||
u, ok := users[kb.CreatorID]
|
||||
if !ok || u == nil {
|
||||
continue
|
||||
}
|
||||
kb.CreatorName = pickUserDisplayName(u)
|
||||
}
|
||||
}
|
||||
|
||||
// pickUserDisplayName picks the field most users will recognise: Username
|
||||
// if present (it's required at registration), Email as a fallback. Used by
|
||||
// both KB and Agent list enrichment so the badge text stays consistent.
|
||||
func pickUserDisplayName(u *types.User) string {
|
||||
if u == nil {
|
||||
return ""
|
||||
}
|
||||
if u.Username != "" {
|
||||
return u.Username
|
||||
}
|
||||
return u.Email
|
||||
}
|
||||
|
||||
// TogglePinKnowledgeBase godoc
|
||||
// @Summary 置顶/取消置顶知识库
|
||||
// @Description 切换知识库的置顶状态
|
||||
|
||||
@@ -102,6 +102,11 @@ type CustomAgent struct {
|
||||
CreatedAt time.Time `yaml:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `yaml:"updated_at" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `yaml:"deleted_at" json:"deleted_at" gorm:"index"`
|
||||
|
||||
// CreatorName 由 list handler 在返回前批量回填,作用同 KnowledgeBase.CreatorName:
|
||||
// 让前端列表卡片区分「我创建」与「同租户其他成员创建」。不落库,内建 agent / 老数据
|
||||
// 仍可能为空。
|
||||
CreatorName string `yaml:"-" json:"creator_name,omitempty" gorm:"-"`
|
||||
}
|
||||
|
||||
// CustomAgentConfig represents the configuration of a custom agent
|
||||
|
||||
@@ -111,6 +111,10 @@ type KnowledgeBase struct {
|
||||
ProcessingCount int64 `yaml:"processing_count" json:"processing_count" gorm:"-"`
|
||||
// ShareCount indicates the number of organizations this knowledge base is shared with (not stored in database)
|
||||
ShareCount int64 `yaml:"share_count" json:"share_count" gorm:"-"`
|
||||
// CreatorName 是 CreatorID 对应用户的展示名(username / email 等),
|
||||
// 仅在列表场景由 handler 批量回填,不落库;为空表示创建者无法解析(用户已删除、
|
||||
// CreatorID 为空的老数据等)。前端用它在卡片来源徽章上做 mine vs tenant 的二分。
|
||||
CreatorName string `yaml:"-" json:"creator_name,omitempty" gorm:"-"`
|
||||
}
|
||||
|
||||
// KnowledgeBaseConfig represents the knowledge base configuration
|
||||
|
||||
Reference in New Issue
Block a user