feat(agent): enhance agent sharing and selection features
- Updated the AgentSelector component to improve agent selection logic, ensuring accurate representation of selected agents. - Introduced new AgentShareSettings component for managing agent sharing with organizations, including UI for selecting organizations and displaying shared agents. - Enhanced API interactions for sharing agents, including new methods for listing and managing agent shares. - Improved localization support for agent sharing features across multiple languages. - Updated various components to reflect changes in agent capabilities and sharing status, enhancing user experience and clarity. This update strengthens the agent management features, providing users with better tools for sharing and selecting agents within organizations.
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
>
|
||||
<div
|
||||
class="agent-option"
|
||||
:class="{ 'selected': currentAgentId === agent.id }"
|
||||
:class="{ 'selected': isMyAgentSelected(agent) }"
|
||||
@click="selectAgent(agent)"
|
||||
>
|
||||
<!-- 快速回答和智能推理使用图标,其他内置智能体使用 avatar -->
|
||||
@@ -51,7 +51,7 @@
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<svg
|
||||
v-if="currentAgentId === agent.id"
|
||||
v-if="isMyAgentSelected(agent)"
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 16 16"
|
||||
@@ -77,7 +77,7 @@
|
||||
</div>
|
||||
<div class="agent-tooltip-title">
|
||||
<span class="agent-tooltip-name">{{ agent.name }}</span>
|
||||
<span v-if="currentAgentId === agent.id" class="agent-tooltip-selected">{{ $t('agent.selector.current') }}</span>
|
||||
<span v-if="isMyAgentSelected(agent)" class="agent-tooltip-selected">{{ $t('agent.selector.current') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="agent-tooltip-desc">{{ agent.description || $t('agent.noDescription') }}</p>
|
||||
@@ -86,6 +86,22 @@
|
||||
<TIcon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'" size="12px" />
|
||||
<span>{{ agent.config?.agent_mode === 'smart-reasoning' ? $t('agent.type.agent') : $t('agent.type.normal') }}</span>
|
||||
</div>
|
||||
<div v-if="getKbCapability(agent)" class="capability-item">
|
||||
<TIcon name="folder" size="12px" />
|
||||
<span>{{ getKbCapability(agent) }}</span>
|
||||
</div>
|
||||
<div v-if="agent.config?.web_search_enabled" class="capability-item">
|
||||
<TIcon name="internet" size="12px" />
|
||||
<span>{{ $t('agent.capabilities.webSearchOn') }}</span>
|
||||
</div>
|
||||
<div v-if="getMcpCapability(agent)" class="capability-item">
|
||||
<TIcon name="extension" size="12px" />
|
||||
<span>{{ getMcpCapability(agent) }}</span>
|
||||
</div>
|
||||
<div v-if="agent.config?.multi_turn_enabled" class="capability-item">
|
||||
<TIcon name="chat-bubble" size="12px" />
|
||||
<span>{{ $t('agent.capabilities.multiTurn') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -105,7 +121,7 @@
|
||||
>
|
||||
<div
|
||||
class="agent-option"
|
||||
:class="{ 'selected': currentAgentId === agent.id }"
|
||||
:class="{ 'selected': isMyAgentSelected(agent) }"
|
||||
@click="selectAgent(agent)"
|
||||
>
|
||||
<AgentAvatar :name="agent.name" size="small" />
|
||||
@@ -117,7 +133,7 @@
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<svg
|
||||
v-if="currentAgentId === agent.id"
|
||||
v-if="isMyAgentSelected(agent)"
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 16 16"
|
||||
@@ -134,7 +150,7 @@
|
||||
<AgentAvatar :name="agent.name" size="small" />
|
||||
<div class="agent-tooltip-title">
|
||||
<span class="agent-tooltip-name">{{ agent.name }}</span>
|
||||
<span v-if="currentAgentId === agent.id" class="agent-tooltip-selected">{{ $t('agent.selector.current') }}</span>
|
||||
<span v-if="isMyAgentSelected(agent)" class="agent-tooltip-selected">{{ $t('agent.selector.current') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="agent-tooltip-desc">{{ agent.description || $t('agent.noDescription') }}</p>
|
||||
@@ -151,9 +167,9 @@
|
||||
<TIcon name="internet" size="12px" />
|
||||
<span>{{ $t('agent.capabilities.webSearchOn') }}</span>
|
||||
</div>
|
||||
<div v-if="agent.config?.mcp_services?.length || agent.config?.mcp_selection_mode === 'all'" class="capability-item">
|
||||
<div v-if="getMcpCapability(agent)" class="capability-item">
|
||||
<TIcon name="extension" size="12px" />
|
||||
<span>{{ $t('agent.capabilities.mcpEnabled') }}</span>
|
||||
<span>{{ getMcpCapability(agent) }}</span>
|
||||
</div>
|
||||
<div v-if="agent.config?.multi_turn_enabled" class="capability-item">
|
||||
<TIcon name="chat-bubble" size="12px" />
|
||||
@@ -165,8 +181,87 @@
|
||||
</t-popup>
|
||||
</div>
|
||||
|
||||
<!-- 共享给我分组 -->
|
||||
<div v-if="sharedAgentsList.length > 0" class="agent-group">
|
||||
<div class="agent-group-title">{{ $t('agent.tabs.sharedToMe') }}</div>
|
||||
<t-popup
|
||||
v-for="shared in sharedAgentsList"
|
||||
:key="`${shared.agent.id}-${shared.source_tenant_id}`"
|
||||
placement="right"
|
||||
trigger="hover"
|
||||
:show-arrow="true"
|
||||
:overlay-inner-class-name="'agent-tooltip-popup'"
|
||||
>
|
||||
<div
|
||||
class="agent-option"
|
||||
:class="{ 'selected': isSharedAgentSelected(shared) }"
|
||||
@click="selectSharedAgent(shared)"
|
||||
>
|
||||
<AgentAvatar :name="shared.agent.name" size="small" />
|
||||
<span class="agent-option-name">{{ shared.agent.name }}</span>
|
||||
<span class="shared-tag">{{ $t('agent.selector.sharedLabel') }}</span>
|
||||
<div class="agent-option-actions">
|
||||
<svg
|
||||
v-if="isSharedAgentSelected(shared)"
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 16 16"
|
||||
fill="currentColor"
|
||||
class="check-icon"
|
||||
>
|
||||
<path d="M13.5 4.5L6 12L2.5 8.5L3.5 7.5L6 10L12.5 3.5L13.5 4.5Z"/>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="agent-tooltip-content">
|
||||
<div class="agent-tooltip-header">
|
||||
<AgentAvatar :name="shared.agent.name" size="small" />
|
||||
<div class="agent-tooltip-title">
|
||||
<span class="agent-tooltip-name">{{ shared.agent.name }}</span>
|
||||
<span v-if="isSharedAgentSelected(shared)" class="agent-tooltip-selected">{{ $t('agent.selector.current') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="agent-tooltip-desc">{{ shared.agent.description || $t('agent.noDescription') }}</p>
|
||||
<div class="agent-tooltip-capabilities">
|
||||
<div class="capability-item">
|
||||
<TIcon :name="shared.agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'" size="12px" />
|
||||
<span>{{ shared.agent.config?.agent_mode === 'smart-reasoning' ? $t('agent.type.agent') : $t('agent.type.normal') }}</span>
|
||||
</div>
|
||||
<div v-if="getKbCapability(shared.agent)" class="capability-item">
|
||||
<TIcon name="folder" size="12px" />
|
||||
<span>{{ getKbCapability(shared.agent) }}</span>
|
||||
</div>
|
||||
<div v-if="shared.agent.config?.web_search_enabled" class="capability-item">
|
||||
<TIcon name="internet" size="12px" />
|
||||
<span>{{ $t('agent.capabilities.webSearchOn') }}</span>
|
||||
</div>
|
||||
<div v-if="getMcpCapability(shared.agent)" class="capability-item">
|
||||
<TIcon name="extension" size="12px" />
|
||||
<span>{{ getMcpCapability(shared.agent) }}</span>
|
||||
</div>
|
||||
<div v-if="shared.agent.config?.multi_turn_enabled" class="capability-item">
|
||||
<TIcon name="chat-bubble" size="12px" />
|
||||
<span>{{ $t('agent.capabilities.multiTurn') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="shared.org_name || shared.shared_by_username" class="agent-tooltip-meta-list">
|
||||
<div v-if="shared.org_name" class="agent-tooltip-meta-row">
|
||||
<img src="@/assets/img/organization-green.svg" class="agent-tooltip-meta-icon" alt="" aria-hidden="true" />
|
||||
<span class="agent-tooltip-meta-text">{{ shared.org_name }}</span>
|
||||
</div>
|
||||
<div v-if="shared.shared_by_username" class="agent-tooltip-meta-row">
|
||||
<img src="@/assets/img/user.svg" class="agent-tooltip-meta-icon" alt="" aria-hidden="true" />
|
||||
<span class="agent-tooltip-meta-text">{{ shared.shared_by_username }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<div v-if="builtinAgents.length === 0 && customAgents.length === 0" class="agent-option empty">
|
||||
<div v-if="builtinAgents.length === 0 && customAgents.length === 0 && sharedAgentsList.length === 0" class="agent-option empty">
|
||||
{{ $t('agent.noAgents') }}
|
||||
</div>
|
||||
</div>
|
||||
@@ -176,34 +271,43 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch, onMounted, nextTick } from 'vue';
|
||||
import { ref, computed, watch, nextTick } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { Icon as TIcon, Popup as TPopup, Tooltip as TTooltip } from 'tdesign-vue-next';
|
||||
import { listAgents, type CustomAgent, BUILTIN_QUICK_ANSWER_ID, BUILTIN_SMART_REASONING_ID } from '@/api/agent';
|
||||
import { type CustomAgent, BUILTIN_QUICK_ANSWER_ID, BUILTIN_SMART_REASONING_ID } from '@/api/agent';
|
||||
import AgentAvatar from '@/components/AgentAvatar.vue';
|
||||
import { useOrganizationStore } from '@/stores/organization';
|
||||
import { useSettingsStore } from '@/stores/settings';
|
||||
import type { SharedAgentInfo } from '@/api/organization';
|
||||
|
||||
const { t } = useI18n();
|
||||
const router = useRouter();
|
||||
const orgStore = useOrganizationStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean;
|
||||
anchorEl?: HTMLElement;
|
||||
currentAgentId: string;
|
||||
/** 由父组件加载的智能体列表,避免下拉打开时重复请求 agents / shared-agents */
|
||||
agents?: CustomAgent[];
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'close'): void;
|
||||
(e: 'select', agent: CustomAgent): void;
|
||||
(e: 'select', agent: CustomAgent, sourceTenantId?: string): void;
|
||||
}>();
|
||||
|
||||
const agents = ref<CustomAgent[]>([]);
|
||||
const dropdownStyle = ref<Record<string, string>>({});
|
||||
|
||||
// 使用父组件传入的 agents,避免与父组件重复请求
|
||||
const agentsList = computed(() => props.agents ?? []);
|
||||
|
||||
// 内置智能体(从 API 获取,对特定 ID 使用本地化名称)
|
||||
const builtinAgents = computed(() => {
|
||||
// 从 API 获取的内置智能体
|
||||
const apiBuiltins = agents.value.filter(a => a.is_builtin);
|
||||
const apiBuiltins = agentsList.value.filter(a => a.is_builtin);
|
||||
|
||||
// 对特定内置智能体使用本地化名称和描述
|
||||
return apiBuiltins.map(agent => {
|
||||
@@ -225,11 +329,24 @@ const builtinAgents = computed(() => {
|
||||
});
|
||||
});
|
||||
|
||||
// 自定义智能体
|
||||
// 自定义智能体(我的)
|
||||
const customAgents = computed(() => {
|
||||
return agents.value.filter(a => !a.is_builtin);
|
||||
return agentsList.value.filter(a => !a.is_builtin);
|
||||
});
|
||||
|
||||
// 共享给我的智能体
|
||||
const sharedAgentsList = computed<SharedAgentInfo[]>(() => orgStore.sharedAgents || []);
|
||||
|
||||
// 当前选中的来源租户(共享智能体时)
|
||||
const currentAgentSourceTenantId = computed(() => settingsStore.selectedAgentSourceTenantId ?? null);
|
||||
|
||||
const isSharedAgentSelected = (shared: SharedAgentInfo) =>
|
||||
props.currentAgentId === shared.agent.id && currentAgentSourceTenantId.value === String(shared.source_tenant_id);
|
||||
|
||||
// 我的智能体(内置或自定义)选中态:仅当未选共享来源时
|
||||
const isMyAgentSelected = (agent: CustomAgent) =>
|
||||
props.currentAgentId === agent.id && !currentAgentSourceTenantId.value;
|
||||
|
||||
// 获取知识库能力描述
|
||||
const getKbCapability = (agent: CustomAgent): string => {
|
||||
const config = agent.config || {};
|
||||
@@ -243,21 +360,31 @@ const getKbCapability = (agent: CustomAgent): string => {
|
||||
return '';
|
||||
};
|
||||
|
||||
// 加载智能体列表
|
||||
const loadAgents = async () => {
|
||||
try {
|
||||
const response = await listAgents();
|
||||
agents.value = response.data || [];
|
||||
} catch (error) {
|
||||
console.error('Failed to load agents:', error);
|
||||
// 获取 MCP 能力描述(更详细:全部 / 指定 N 个)
|
||||
const getMcpCapability = (agent: CustomAgent): string => {
|
||||
const config = agent.config || {};
|
||||
if (config.mcp_selection_mode === 'none' || (!config.mcp_services?.length && config.mcp_selection_mode !== 'all')) {
|
||||
return '';
|
||||
}
|
||||
if (config.mcp_selection_mode === 'all') {
|
||||
return t('agent.detail.shareScope.mcpAll');
|
||||
}
|
||||
if (config.mcp_services?.length) {
|
||||
return t('agent.detail.shareScope.mcpSelected', { count: config.mcp_services.length });
|
||||
}
|
||||
return t('agent.capabilities.mcpEnabled');
|
||||
};
|
||||
|
||||
// 选择智能体
|
||||
// 选择智能体(我的或内置)
|
||||
const selectAgent = (agent: CustomAgent) => {
|
||||
emit('select', agent);
|
||||
};
|
||||
|
||||
// 选择共享智能体
|
||||
const selectSharedAgent = (shared: SharedAgentInfo) => {
|
||||
emit('select', shared.agent as CustomAgent, String(shared.source_tenant_id));
|
||||
};
|
||||
|
||||
// 跳转到智能体设置页面
|
||||
const goToSettings = (agent: CustomAgent) => {
|
||||
emit('close');
|
||||
@@ -325,21 +452,14 @@ const updateDropdownPosition = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 监听显示状态
|
||||
// 监听显示状态(仅更新位置,数据由父组件加载后通过 props.agents 传入)
|
||||
watch(() => props.visible, (newVal) => {
|
||||
if (newVal) {
|
||||
loadAgents();
|
||||
nextTick(() => {
|
||||
updateDropdownPosition();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
if (props.visible) {
|
||||
loadAgents();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@@ -474,6 +594,41 @@ onMounted(() => {
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.shared-tag {
|
||||
font-size: 10px;
|
||||
color: var(--td-text-color-placeholder, #999);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.agent-tooltip-meta-list {
|
||||
margin-top: 8px;
|
||||
padding-top: 8px;
|
||||
border-top: 1px solid var(--td-component-stroke, #f0f0f0);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.agent-tooltip-meta-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 11px;
|
||||
color: var(--td-text-color-placeholder, #999);
|
||||
}
|
||||
|
||||
.agent-tooltip-meta-icon {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.agent-tooltip-meta-text {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.builtin-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -0,0 +1,510 @@
|
||||
<template>
|
||||
<div class="section-content">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">{{ $t('organization.share.title') }}</h3>
|
||||
<p class="section-desc">{{ $t('organization.share.agentShareDesc') || '将智能体共享到空间,空间成员可使用该智能体' }}</p>
|
||||
</div>
|
||||
<!-- 共享范围说明:当传入 agent 时展示,仅提示 + 变更同步说明,不列具体开关 -->
|
||||
<div v-if="agent?.config" class="share-scope-block">
|
||||
<h4 class="share-scope-title">{{ $t('agent.shareScope.title') }}</h4>
|
||||
<p class="share-scope-desc">{{ $t('agent.shareScope.desc') }}</p>
|
||||
</div>
|
||||
<div class="section-body">
|
||||
<div class="share-form">
|
||||
<div class="form-item">
|
||||
<label class="form-label">{{ $t('organization.share.selectOrg') }}</label>
|
||||
<div class="share-input-row">
|
||||
<t-select
|
||||
v-model="selectedOrgId"
|
||||
:placeholder="$t('organization.share.selectOrgPlaceholder')"
|
||||
:loading="loadingOrgs"
|
||||
class="org-select org-select-dropdown"
|
||||
:popup-props="{ overlayClassName: 'org-select-dropdown-popup' }"
|
||||
>
|
||||
<t-option
|
||||
v-for="org in availableOrganizations"
|
||||
:key="org.id"
|
||||
:value="org.id"
|
||||
:label="org.name"
|
||||
>
|
||||
<div class="org-option-content">
|
||||
<div class="org-option-icon-wrap">
|
||||
<SpaceAvatar :name="org.name" :avatar="org.avatar" size="small" />
|
||||
</div>
|
||||
<div class="org-option-body">
|
||||
<div class="org-option-header">
|
||||
<span class="org-option-name">{{ org.name }}</span>
|
||||
<t-tag v-if="org.is_owner" theme="primary" size="small" variant="light">
|
||||
{{ $t('organization.owner') }}
|
||||
</t-tag>
|
||||
<t-tag v-else-if="org.my_role" :theme="org.my_role === 'admin' ? 'warning' : 'default'" size="small" variant="light">
|
||||
{{ $t(`organization.role.${org.my_role}`) }}
|
||||
</t-tag>
|
||||
</div>
|
||||
<div class="org-option-meta">
|
||||
<span class="org-meta-tag">
|
||||
<t-icon name="user" class="org-meta-icon org-meta-icon-user" />
|
||||
{{ org.member_count ?? 0 }}
|
||||
</span>
|
||||
<span class="org-meta-tag">
|
||||
<img src="@/assets/img/zhishiku.svg" class="org-meta-icon org-meta-icon-kb" alt="" aria-hidden="true" />
|
||||
{{ org.share_count ?? 0 }}
|
||||
</span>
|
||||
<span class="org-meta-tag">
|
||||
<img src="@/assets/img/organization-grey.svg" class="org-meta-icon org-meta-icon-kb" alt="" aria-hidden="true" />
|
||||
{{ org.agent_share_count ?? 0 }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t-option>
|
||||
</t-select>
|
||||
<t-button
|
||||
theme="primary"
|
||||
:loading="submitting"
|
||||
:disabled="!selectedOrgId"
|
||||
@click="handleShare"
|
||||
>
|
||||
{{ $t('knowledgeEditor.share.addShare') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="shares-section">
|
||||
<div class="shares-header">
|
||||
<span class="shares-title">{{ $t('organization.share.sharedTo') }}</span>
|
||||
<span class="shares-count">{{ shares.length }}</span>
|
||||
</div>
|
||||
<div v-if="loadingShares" class="shares-loading">
|
||||
<t-loading size="small" />
|
||||
<span>{{ $t('common.loading') }}</span>
|
||||
</div>
|
||||
<div v-else-if="shares.length === 0" class="shares-empty">
|
||||
<t-icon name="share" class="empty-icon" />
|
||||
<span>{{ $t('organization.share.noShares') }}</span>
|
||||
</div>
|
||||
<div v-else class="shares-list">
|
||||
<div v-for="share in shares" :key="share.id" class="share-item">
|
||||
<div class="share-info">
|
||||
<div class="share-info-top">
|
||||
<div class="share-org">
|
||||
<SpaceAvatar
|
||||
:name="share.organization_name || ''"
|
||||
:avatar="orgStore.organizations.find(o => o.id === share.organization_id)?.avatar"
|
||||
size="small"
|
||||
/>
|
||||
<span class="org-name">{{ share.organization_name }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="share-item-meta">
|
||||
<span class="org-meta-tag">
|
||||
<t-icon name="user" class="org-meta-icon org-meta-icon-user" />
|
||||
{{ getOrgForShare(share.organization_id)?.member_count ?? 0 }}
|
||||
</span>
|
||||
<span class="org-meta-tag">
|
||||
<img src="@/assets/img/zhishiku.svg" class="org-meta-icon org-meta-icon-kb" alt="" aria-hidden="true" />
|
||||
{{ getOrgForShare(share.organization_id)?.share_count ?? 0 }}
|
||||
</span>
|
||||
<t-tooltip :content="$t('organization.share.spaceAgentShareCountTip')" placement="top">
|
||||
<span class="org-meta-tag">
|
||||
<img src="@/assets/img/agent.svg" class="org-meta-icon org-meta-icon-kb" alt="" aria-hidden="true" />
|
||||
{{ getOrgForShare(share.organization_id)?.agent_share_count ?? 0 }}
|
||||
</span>
|
||||
</t-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
<div class="share-actions">
|
||||
<t-popconfirm
|
||||
:content="$t('knowledgeEditor.share.unshareConfirm', { name: share.organization_name })"
|
||||
@confirm="handleUnshare(share)"
|
||||
>
|
||||
<t-button variant="text" theme="danger" size="small">
|
||||
<t-icon name="delete" />
|
||||
</t-button>
|
||||
</t-popconfirm>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch, onMounted } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useOrganizationStore } from '@/stores/organization'
|
||||
import { shareAgent, listAgentShares, removeAgentShare } from '@/api/organization'
|
||||
import type { AgentShareResponse } from '@/api/organization'
|
||||
import type { CustomAgent } from '@/api/agent'
|
||||
import SpaceAvatar from '@/components/SpaceAvatar.vue'
|
||||
|
||||
const { t } = useI18n()
|
||||
const orgStore = useOrganizationStore()
|
||||
|
||||
function getOrgForShare(organizationId: string) {
|
||||
return orgStore.organizations.find(o => o.id === organizationId)
|
||||
}
|
||||
|
||||
interface Props {
|
||||
agentId: string
|
||||
/** 当前智能体(用于展示共享范围说明) */
|
||||
agent?: CustomAgent | null
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const loadingOrgs = ref(false)
|
||||
const loadingShares = ref(false)
|
||||
const submitting = ref(false)
|
||||
const selectedOrgId = ref('')
|
||||
const shares = ref<(AgentShareResponse & { organization_name?: string })[]>([])
|
||||
|
||||
const availableOrganizations = computed(() => {
|
||||
const sharedOrgIds = new Set(shares.value.map(s => s.organization_id))
|
||||
return orgStore.organizations.filter(
|
||||
(org) =>
|
||||
!sharedOrgIds.has(org.id) &&
|
||||
(org.is_owner === true || org.my_role === 'admin' || org.my_role === 'editor')
|
||||
)
|
||||
})
|
||||
|
||||
async function loadOrganizations() {
|
||||
loadingOrgs.value = true
|
||||
try {
|
||||
await orgStore.fetchOrganizations()
|
||||
} finally {
|
||||
loadingOrgs.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadShares() {
|
||||
if (!props.agentId) return
|
||||
loadingShares.value = true
|
||||
try {
|
||||
const result = await listAgentShares(props.agentId)
|
||||
if (result.success && result.data) {
|
||||
const sharesData = (result.data as any).shares || result.data
|
||||
const sharesList = Array.isArray(sharesData) ? sharesData : []
|
||||
shares.value = sharesList.map((share: AgentShareResponse) => ({
|
||||
...share,
|
||||
organization_name: share.organization_name || orgStore.organizations.find(o => o.id === share.organization_id)?.name || share.organization_id
|
||||
}))
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to load agent shares:', e)
|
||||
} finally {
|
||||
loadingShares.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleShare() {
|
||||
if (!selectedOrgId.value) return
|
||||
submitting.value = true
|
||||
try {
|
||||
const result = await shareAgent(props.agentId, {
|
||||
organization_id: selectedOrgId.value,
|
||||
permission: 'viewer'
|
||||
})
|
||||
if (result.success) {
|
||||
MessagePlugin.success(t('organization.share.shareSuccess'))
|
||||
selectedOrgId.value = ''
|
||||
await loadShares()
|
||||
} else {
|
||||
MessagePlugin.error(result.message || t('organization.share.shareFailed'))
|
||||
}
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('organization.share.shareFailed'))
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleUnshare(share: AgentShareResponse) {
|
||||
try {
|
||||
const result = await removeAgentShare(props.agentId, share.id)
|
||||
if (result.success) {
|
||||
MessagePlugin.success(t('organization.share.unshareSuccess'))
|
||||
await loadShares()
|
||||
} else {
|
||||
MessagePlugin.error(result.message || t('organization.share.unshareFailed'))
|
||||
}
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(e?.message || t('organization.share.unshareFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => props.agentId, async (newId) => {
|
||||
if (newId) await Promise.all([loadOrganizations(), loadShares()])
|
||||
}, { immediate: true })
|
||||
|
||||
onMounted(async () => {
|
||||
if (props.agentId) await Promise.all([loadOrganizations(), loadShares()])
|
||||
})
|
||||
|
||||
defineExpose({ loadShares })
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.section-content { .section-header { margin-bottom: 20px; } .section-title { margin: 0 0 8px 0; font-size: 16px; font-weight: 600; } .section-desc { margin: 0; font-size: 14px; color: #00000066; } }
|
||||
.share-form { margin-bottom: 24px; padding-bottom: 24px; border-bottom: 1px solid #f0f0f0; }
|
||||
.form-item {
|
||||
.form-label {
|
||||
display: block;
|
||||
margin-bottom: 12px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
.share-input-row {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
.org-select { flex: 1; min-width: 240px; }
|
||||
}
|
||||
.shares-section { margin-bottom: 24px; }
|
||||
.shares-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
.shares-title {
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #000000e6;
|
||||
}
|
||||
.shares-count {
|
||||
padding: 2px 8px;
|
||||
background: #f5f5f5;
|
||||
border-radius: 10px;
|
||||
font-size: 12px;
|
||||
color: #00000066;
|
||||
}
|
||||
}
|
||||
.shares-loading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
padding: 32px;
|
||||
color: #00000066;
|
||||
font-size: 14px;
|
||||
}
|
||||
.shares-empty {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
padding: 40px 20px;
|
||||
background: #fafafa;
|
||||
border-radius: 8px;
|
||||
color: #00000066;
|
||||
.empty-icon { font-size: 32px; opacity: 0.5; }
|
||||
}
|
||||
.shares-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
max-height: 320px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.share-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px 16px;
|
||||
background: #fafafa;
|
||||
border: 1px solid #f0f0f0;
|
||||
border-radius: 8px;
|
||||
transition: background 0.2s ease, border-color 0.2s ease;
|
||||
&:hover {
|
||||
background: #f5f5f5;
|
||||
border-color: #e8e8e8;
|
||||
}
|
||||
}
|
||||
.share-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.share-info-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
.share-org {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
.org-name {
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #000000e6;
|
||||
}
|
||||
}
|
||||
.share-item-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
color: #00000099;
|
||||
.org-meta-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
padding: 2px 6px;
|
||||
background: #f0f0f0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.org-meta-icon {
|
||||
flex-shrink: 0;
|
||||
vertical-align: middle;
|
||||
color: #00000099;
|
||||
}
|
||||
.org-meta-icon-user {
|
||||
font-size: 12px;
|
||||
}
|
||||
.org-meta-icon-kb {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
opacity: 0.75;
|
||||
}
|
||||
}
|
||||
.share-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
.permission-change-select { width: 100px; }
|
||||
}
|
||||
|
||||
.share-scope-block {
|
||||
margin-bottom: 24px;
|
||||
padding: 16px;
|
||||
background: #f8faf9;
|
||||
border: 1px solid #e8f5ed;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.share-scope-title {
|
||||
margin: 0 0 6px 0;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #1a1a1a;
|
||||
}
|
||||
.share-scope-desc {
|
||||
margin: 0 0 12px 0;
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
// 与知识库设置中空间下拉一致的选项样式
|
||||
:deep(.t-select-option) {
|
||||
height: auto;
|
||||
align-items: center;
|
||||
padding: 6px 12px;
|
||||
border-radius: 4px;
|
||||
margin: 1px 6px;
|
||||
transition: background 0.15s ease;
|
||||
}
|
||||
:deep(.t-select-option:hover),
|
||||
:deep(.t-select-option.t-is-selected) {
|
||||
background: #f0f7ff;
|
||||
}
|
||||
:deep(.t-select-option__content) {
|
||||
width: 100%;
|
||||
}
|
||||
.org-option-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 0;
|
||||
min-width: 260px;
|
||||
width: 100%;
|
||||
}
|
||||
.org-option-icon-wrap {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.org-option-body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.org-option-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
.org-option-name {
|
||||
font-family: "PingFang SC";
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: #000000e6;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.org-option-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 12px;
|
||||
color: #00000099;
|
||||
|
||||
.org-meta-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
padding: 0px 4px;
|
||||
background: #f0f0f0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.org-meta-icon {
|
||||
flex-shrink: 0;
|
||||
vertical-align: middle;
|
||||
color: #00000099;
|
||||
}
|
||||
|
||||
.org-meta-icon-user {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.org-meta-icon-kb {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
opacity: 0.75;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="less">
|
||||
.org-select-dropdown-popup.t-select__dropdown {
|
||||
padding: 4px 0;
|
||||
max-height: 320px;
|
||||
overflow-y: auto;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
.org-select-dropdown-popup .t-select-option {
|
||||
height: auto;
|
||||
align-items: center;
|
||||
padding: 6px 12px;
|
||||
border-radius: 4px;
|
||||
margin: 1px 6px;
|
||||
}
|
||||
.org-select-dropdown-popup .t-select-option__content {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -39,7 +39,16 @@ const selectedAgentId = computed({
|
||||
set: (val: string) => settingsStore.selectAgent(val)
|
||||
});
|
||||
const selectedAgent = computed(() => {
|
||||
return agents.value.find(a => a.id === selectedAgentId.value) || {
|
||||
const mine = agents.value.find(a => a.id === selectedAgentId.value);
|
||||
if (mine) return mine;
|
||||
const sourceTenantId = settingsStore.selectedAgentSourceTenantId;
|
||||
if (sourceTenantId && orgStore.sharedAgents?.length) {
|
||||
const shared = orgStore.sharedAgents.find(
|
||||
s => s.agent.id === selectedAgentId.value && String(s.source_tenant_id) === sourceTenantId
|
||||
);
|
||||
if (shared?.agent) return shared.agent as CustomAgent;
|
||||
}
|
||||
return {
|
||||
id: BUILTIN_QUICK_ANSWER_ID,
|
||||
name: t('input.normalMode'),
|
||||
is_builtin: true,
|
||||
@@ -80,25 +89,49 @@ const agentKnowledgeBases = computed(() => {
|
||||
return currentAgentConfig.value?.knowledge_bases || [];
|
||||
});
|
||||
|
||||
// 当智能体改变时,将智能体配置的知识库同步到 store
|
||||
// 这样用户可以移除这些知识库
|
||||
watch([selectedAgentId, agentKnowledgeBases], ([newAgentId, newAgentKbs], [oldAgentId]) => {
|
||||
if (newAgentId !== oldAgentId && newAgentKbs && newAgentKbs.length > 0) {
|
||||
// 智能体切换了,将新智能体配置的知识库添加到 store
|
||||
const currentSelected = settingsStore.settings.selectedKnowledgeBases || [];
|
||||
const toAdd = newAgentKbs.filter((id: string) => !currentSelected.includes(id));
|
||||
if (toAdd.length > 0) {
|
||||
settingsStore.selectKnowledgeBases([...currentSelected, ...toAdd]);
|
||||
}
|
||||
}
|
||||
}, { immediate: true });
|
||||
|
||||
// 智能体的知识库选择模式
|
||||
const agentKBSelectionMode = computed(() => {
|
||||
if (!hasAgentConfig.value) return null; // null 表示不受智能体控制
|
||||
return currentAgentConfig.value?.kb_selection_mode || 'all';
|
||||
});
|
||||
|
||||
// 当智能体改变时,模型、网络搜索、可@知识库列表均跟随新智能体配置
|
||||
// 知识库:用新智能体配置的列表替换当前选中,使已选与可@列表一致(含共享智能体)
|
||||
watch([selectedAgentId, agentKnowledgeBases, agentKBSelectionMode], ([newAgentId, newAgentKbs, newKbMode], [oldAgentId]) => {
|
||||
if (newAgentId !== oldAgentId && oldAgentId !== undefined) {
|
||||
if (newKbMode === 'none') {
|
||||
settingsStore.selectKnowledgeBases([]);
|
||||
} else {
|
||||
settingsStore.selectKnowledgeBases(newAgentKbs && newAgentKbs.length > 0 ? [...newAgentKbs] : []);
|
||||
}
|
||||
// 若 @ 面板已打开,刷新可@列表以立即反映新智能体的知识库范围
|
||||
if (showMention.value) {
|
||||
loadMentionItems(mentionQuery.value, true);
|
||||
}
|
||||
}
|
||||
}, { immediate: true });
|
||||
|
||||
// 共享智能体时预取该智能体知识库列表,使已选标签在未打开 @ 时也能显示共享空间角标
|
||||
watch([selectedAgentId, () => settingsStore.selectedAgentSourceTenantId], async ([agentId, sourceTenantId]) => {
|
||||
if (sourceTenantId && agentId) {
|
||||
try {
|
||||
const res: any = await listKnowledgeBases({ agent_id: agentId });
|
||||
const list = res?.data && Array.isArray(res.data) ? res.data : [];
|
||||
sharedAgentKbList.value = list.map((kb: any) => ({
|
||||
id: kb.id,
|
||||
name: kb.name,
|
||||
type: kb.type || 'document',
|
||||
knowledge_count: kb.knowledge_count,
|
||||
chunk_count: kb.chunk_count
|
||||
}));
|
||||
} catch {
|
||||
sharedAgentKbList.value = [];
|
||||
}
|
||||
} else {
|
||||
sharedAgentKbList.value = [];
|
||||
}
|
||||
}, { immediate: true });
|
||||
|
||||
// 智能体是否启用了网络搜索
|
||||
const agentWebSearchEnabled = computed(() => {
|
||||
if (!hasAgentConfig.value) return null; // null 表示不受智能体控制
|
||||
@@ -159,6 +192,20 @@ const mentionLoading = ref(false);
|
||||
const mentionOffset = ref(0);
|
||||
const MENTION_PAGE_SIZE = 20;
|
||||
|
||||
// 共享智能体时用于标识「共享空间」的展示名(组织名或共享者),供 @ 列表与已选标签显示角标
|
||||
const sharedAgentOrgName = computed(() => {
|
||||
const sourceTenantId = settingsStore.selectedAgentSourceTenantId;
|
||||
const agentId = selectedAgentId.value;
|
||||
if (!sourceTenantId || !agentId || !orgStore.sharedAgents?.length) return '';
|
||||
const shared = orgStore.sharedAgents.find(
|
||||
(s: any) => s.agent?.id === agentId && String(s.source_tenant_id) === sourceTenantId
|
||||
);
|
||||
return shared?.org_name || shared?.shared_by_username || '';
|
||||
});
|
||||
|
||||
// 共享智能体下的知识库列表(来自 listKnowledgeBases(agent_id)),用于已选知识库展示与 org 角标
|
||||
const sharedAgentKbList = ref<Array<{ id: string; name: string; type?: string; knowledge_count?: number; chunk_count?: number }>>([]);
|
||||
|
||||
const props = defineProps({
|
||||
isReplying: {
|
||||
type: Boolean,
|
||||
@@ -184,7 +231,7 @@ const isWebSearchConfigured = ref(false);
|
||||
const knowledgeBases = ref<Array<{ id: string; name: string; type?: 'document' | 'faq'; knowledge_count?: number; chunk_count?: number }>>([]);
|
||||
const fileList = ref<Array<{ id: string; name: string }>>([]);
|
||||
|
||||
// 选中的知识库:包含自己的 + 别人共享的(用于展示已选列表)
|
||||
// 选中的知识库:包含自己的 + 组织共享的 + 共享智能体下的(用于展示已选列表与 org 角标)
|
||||
const selectedKbs = computed(() => {
|
||||
const own = knowledgeBases.value.filter(kb => selectedKbIds.value.includes(kb.id));
|
||||
const sharedList = orgStore.sharedKnowledgeBases || [];
|
||||
@@ -200,7 +247,18 @@ const selectedKbs = computed(() => {
|
||||
}));
|
||||
const ownIds = new Set(own.map(kb => kb.id));
|
||||
const sharedOnly = sharedMapped.filter((kb: any) => !ownIds.has(kb.id));
|
||||
return [...own, ...sharedOnly];
|
||||
const sharedOnlyIds = new Set(sharedOnly.map((kb: any) => kb.id));
|
||||
// 共享智能体下的知识库:从 sharedAgentKbList 中取在选中列表里的,并打上共享空间标识
|
||||
const agentOrg = sharedAgentOrgName.value;
|
||||
const sharedFromAgent = (sharedAgentKbList.value || []).filter(kb => selectedKbIds.value.includes(kb.id) && !ownIds.has(kb.id) && !sharedOnlyIds.has(kb.id)).map(kb => ({
|
||||
id: kb.id,
|
||||
name: kb.name,
|
||||
type: kb.type || 'document',
|
||||
knowledge_count: kb.knowledge_count,
|
||||
chunk_count: kb.chunk_count,
|
||||
org_name: agentOrg || ''
|
||||
}));
|
||||
return [...own, ...sharedOnly, ...sharedFromAgent];
|
||||
});
|
||||
|
||||
const selectedFiles = computed(() => {
|
||||
@@ -226,13 +284,18 @@ const selectedFiles = computed(() => {
|
||||
isAgentConfigured: agentKbIds.includes(kb.id)
|
||||
}));
|
||||
|
||||
// 用户选择的文件(根据 fileIdToKbId + 共享列表补全 org_name,用于角标)
|
||||
// 用户选择的文件(根据 fileIdToKbId + 共享列表/共享智能体补全 org_name,用于角标)
|
||||
const sharedKbOrgMap: Record<string, string> = {};
|
||||
(orgStore.sharedKnowledgeBases || []).forEach((s: any) => {
|
||||
if (s.knowledge_base?.id != null && s.org_name) {
|
||||
sharedKbOrgMap[String(s.knowledge_base.id)] = s.org_name;
|
||||
}
|
||||
});
|
||||
if (sharedAgentOrgName.value) {
|
||||
(sharedAgentKbList.value || []).forEach((kb) => {
|
||||
sharedKbOrgMap[String(kb.id)] = sharedAgentOrgName.value;
|
||||
});
|
||||
}
|
||||
const files = selectedFiles.value.map((f: { id: string; name: string }) => {
|
||||
const kbId = fileIdToKbId.value[f.id];
|
||||
const org_name = kbId ? sharedKbOrgMap[String(kbId)] || '' : '';
|
||||
@@ -361,10 +424,11 @@ const loadFiles = async () => {
|
||||
});
|
||||
|
||||
const allNewFiles: Array<{ id: string; name: string }> = [];
|
||||
const runBatch = async (batchIds: string[], kbId?: string) => {
|
||||
const agentIdForBatch = settingsStore.selectedAgentSourceTenantId ? settingsStore.selectedAgentId : undefined;
|
||||
const runBatch = async (batchIds: string[], kbId?: string, agentId?: string) => {
|
||||
const query = new URLSearchParams();
|
||||
batchIds.forEach((id: string) => query.append('ids', id));
|
||||
const res: any = await batchQueryKnowledge(query.toString(), kbId);
|
||||
const res: any = await batchQueryKnowledge(query.toString(), kbId, agentId);
|
||||
if (res.data && Array.isArray(res.data)) {
|
||||
res.data.forEach((f: any) => allNewFiles.push({ id: f.id, name: f.title || f.file_name }));
|
||||
}
|
||||
@@ -374,7 +438,7 @@ const loadFiles = async () => {
|
||||
await runBatch(batchIds, kbId);
|
||||
}
|
||||
if (noKbId.length > 0) {
|
||||
await runBatch(noKbId);
|
||||
await runBatch(noKbId, undefined, agentIdForBatch);
|
||||
}
|
||||
if (allNewFiles.length > 0) {
|
||||
fileList.value = [...fileList.value, ...allNewFiles];
|
||||
@@ -407,11 +471,14 @@ const loadWebSearchConfig = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 加载智能体列表
|
||||
// 加载智能体列表(我的 + 共享,供选中态与就绪检查用)
|
||||
const loadAgents = async () => {
|
||||
try {
|
||||
const response = await listAgents();
|
||||
agents.value = response.data || [];
|
||||
const [agentsRes] = await Promise.all([
|
||||
listAgents(),
|
||||
orgStore.fetchSharedAgents(),
|
||||
]);
|
||||
agents.value = agentsRes.data || [];
|
||||
} catch (error) {
|
||||
console.error('Failed to load agents:', error);
|
||||
}
|
||||
@@ -527,6 +594,16 @@ const selectedModel = computed(() => {
|
||||
return availableModels.value.find(model => model.id === selectedModelId.value);
|
||||
});
|
||||
|
||||
// 模型展示名:本租户列表中有则用名称;若为共享智能体且其 model_id 不在本租户列表中则显示“共享智能体配置的模型”
|
||||
const selectedModelDisplayName = computed(() => {
|
||||
if (selectedModel.value) return selectedModel.value.name;
|
||||
if (!selectedModelId.value) return t('input.notConfigured');
|
||||
const isSharedAgent = !!settingsStore.selectedAgentSourceTenantId;
|
||||
const modelFromAgent = agentModelId.value && agentModelId.value === selectedModelId.value;
|
||||
if (isSharedAgent && modelFromAgent) return t('input.sharedAgentModelLabel');
|
||||
return t('input.notConfigured');
|
||||
});
|
||||
|
||||
const updateModelDropdownPosition = () => {
|
||||
const anchor = modelButtonRef.value;
|
||||
if (!anchor) {
|
||||
@@ -644,33 +721,61 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) =>
|
||||
mentionOffset.value = 0;
|
||||
}
|
||||
|
||||
// 根据智能体的 kb_selection_mode 过滤知识库;合并「自己的」+「共享的」知识库
|
||||
// 根据智能体的 kb_selection_mode 过滤知识库;选中共享智能体时使用该租户下的知识库,否则使用本租户 + 共享给自己的
|
||||
let kbItems: any[] = [];
|
||||
if (!append) {
|
||||
// 自己的知识库(需有 embedding/summary 模型)
|
||||
let availableKbs = [...knowledgeBases.value];
|
||||
// 共享的知识库(有权限的),映射为与 knowledgeBases 同结构便于合并
|
||||
const sharedList = orgStore.sharedKnowledgeBases || [];
|
||||
const sharedKbsForMention = sharedList
|
||||
.filter((s: any) => s.knowledge_base != null)
|
||||
.map((s: any) => ({
|
||||
id: s.knowledge_base.id,
|
||||
name: s.knowledge_base.name,
|
||||
type: s.knowledge_base.type || 'document',
|
||||
knowledge_count: s.knowledge_base.knowledge_count,
|
||||
chunk_count: s.knowledge_base.chunk_count,
|
||||
org_name: s.org_name || ''
|
||||
}));
|
||||
// 去重:若某 KB 既在自己列表又在共享列表,只保留一份(自己的优先)
|
||||
const ownIds = new Set(availableKbs.map((kb: any) => kb.id));
|
||||
sharedKbsForMention.forEach((kb: any) => {
|
||||
if (!ownIds.has(kb.id)) {
|
||||
availableKbs.push(kb);
|
||||
ownIds.add(kb.id);
|
||||
let availableKbs: any[];
|
||||
const sourceTenantId = settingsStore.selectedAgentSourceTenantId;
|
||||
const agentId = selectedAgentId.value;
|
||||
if (sourceTenantId && agentId) {
|
||||
// 共享智能体:按 agent_id 拉取该智能体配置的知识库范围(后端从共享关系解析租户)
|
||||
try {
|
||||
const res: any = await listKnowledgeBases({ agent_id: agentId });
|
||||
const list = res?.data && Array.isArray(res.data) ? res.data : [];
|
||||
const orgLabel = sharedAgentOrgName.value || '';
|
||||
availableKbs = list.map((kb: any) => ({
|
||||
id: kb.id,
|
||||
name: kb.name,
|
||||
type: kb.type || 'document',
|
||||
knowledge_count: kb.knowledge_count,
|
||||
chunk_count: kb.chunk_count,
|
||||
org_name: orgLabel
|
||||
}));
|
||||
sharedAgentKbList.value = list.map((kb: any) => ({
|
||||
id: kb.id,
|
||||
name: kb.name,
|
||||
type: kb.type || 'document',
|
||||
knowledge_count: kb.knowledge_count,
|
||||
chunk_count: kb.chunk_count
|
||||
}));
|
||||
} catch (e) {
|
||||
console.error('[Mention] listKnowledgeBases(agent_id) error:', e);
|
||||
availableKbs = [];
|
||||
sharedAgentKbList.value = [];
|
||||
}
|
||||
});
|
||||
} else {
|
||||
sharedAgentKbList.value = [];
|
||||
availableKbs = [...knowledgeBases.value];
|
||||
const sharedList = orgStore.sharedKnowledgeBases || [];
|
||||
const sharedKbsForMention = sharedList
|
||||
.filter((s: any) => s.knowledge_base != null)
|
||||
.map((s: any) => ({
|
||||
id: s.knowledge_base.id,
|
||||
name: s.knowledge_base.name,
|
||||
type: s.knowledge_base.type || 'document',
|
||||
knowledge_count: s.knowledge_base.knowledge_count,
|
||||
chunk_count: s.knowledge_base.chunk_count,
|
||||
org_name: s.org_name || ''
|
||||
}));
|
||||
const ownIds = new Set(availableKbs.map((kb: any) => kb.id));
|
||||
sharedKbsForMention.forEach((kb: any) => {
|
||||
if (!ownIds.has(kb.id)) {
|
||||
availableKbs.push(kb);
|
||||
ownIds.add(kb.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 如果智能体有配置,根据 kb_selection_mode 过滤
|
||||
if (hasAgentConfig.value) {
|
||||
const kbMode = agentKBSelectionMode.value;
|
||||
if (kbMode === 'none') {
|
||||
@@ -681,7 +786,6 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) =>
|
||||
}
|
||||
}
|
||||
|
||||
// 按查询过滤
|
||||
const kbs = availableKbs.filter((kb: any) =>
|
||||
!q || (kb.name && kb.name.toLowerCase().includes(q.toLowerCase()))
|
||||
);
|
||||
@@ -691,7 +795,7 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) =>
|
||||
type: 'kb' as const,
|
||||
kbType: kb.type || 'document',
|
||||
count: kb.type === 'faq' ? (kb.chunk_count || 0) : (kb.knowledge_count || 0),
|
||||
orgName: kb.org_name || undefined
|
||||
orgName: kb.org_name || sharedAgentOrgName.value || undefined
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -703,35 +807,42 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) =>
|
||||
if (shouldLoadFiles) {
|
||||
mentionLoading.value = true;
|
||||
try {
|
||||
// 将文件类型过滤传递给后端
|
||||
const fileTypesParam = agentSupportedFileTypes.value.length > 0 ? agentSupportedFileTypes.value : undefined;
|
||||
const res: any = await searchKnowledge(q || '', mentionOffset.value, MENTION_PAGE_SIZE, fileTypesParam);
|
||||
const sourceTenantId = settingsStore.selectedAgentSourceTenantId;
|
||||
const agentId = selectedAgentId.value;
|
||||
const searchOptions = sourceTenantId && agentId ? { agent_id: agentId } : undefined;
|
||||
const res: any = await searchKnowledge(
|
||||
q || '',
|
||||
mentionOffset.value,
|
||||
MENTION_PAGE_SIZE,
|
||||
fileTypesParam,
|
||||
searchOptions
|
||||
);
|
||||
console.log('[Mention] searchKnowledge response:', res);
|
||||
if (res.data && Array.isArray(res.data)) {
|
||||
let files = res.data;
|
||||
|
||||
// 如果智能体配置了 kb_selection_mode === 'selected',只显示指定知识库中的文件
|
||||
if (hasAgentConfig.value && agentKBSelectionMode.value === 'selected') {
|
||||
if (!sourceTenantId && hasAgentConfig.value && agentKBSelectionMode.value === 'selected') {
|
||||
const configuredKbIds = agentKnowledgeBases.value;
|
||||
files = files.filter((f: any) => configuredKbIds.includes(f.knowledge_base_id ?? f.kb_id));
|
||||
}
|
||||
// 共享知识库 kb_id -> org_name,用于文件项显示组织角标(key 统一转 string 避免类型不一致)
|
||||
const sharedKbOrgMap: Record<string, string> = {};
|
||||
(orgStore.sharedKnowledgeBases || []).forEach((s: any) => {
|
||||
if (s.knowledge_base?.id != null && s.org_name) {
|
||||
sharedKbOrgMap[String(s.knowledge_base.id)] = s.org_name;
|
||||
}
|
||||
});
|
||||
const agentOrgLabel = sourceTenantId && agentId ? sharedAgentOrgName.value : '';
|
||||
fileItems = files.map((f: any) => {
|
||||
const kbId = f.knowledge_base_id ?? f.kb_id;
|
||||
const kbIdStr = kbId != null ? String(kbId) : '';
|
||||
const fileOrgName = agentOrgLabel || (kbIdStr ? sharedKbOrgMap[kbIdStr] : undefined);
|
||||
return {
|
||||
id: f.id,
|
||||
name: f.title || f.file_name,
|
||||
type: 'file' as const,
|
||||
kbName: f.knowledge_base_name || '',
|
||||
kbId: kbId || undefined,
|
||||
orgName: kbIdStr ? sharedKbOrgMap[kbIdStr] || undefined : undefined
|
||||
orgName: fileOrgName || undefined
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -961,6 +1072,7 @@ const onMentionSelect = (item: any) => {
|
||||
settingsStore.addFile(item.id);
|
||||
if (item.kbId) {
|
||||
fileIdToKbId.value[item.id] = item.kbId;
|
||||
settingsStore.setFileKbMap({ [item.id]: item.kbId });
|
||||
}
|
||||
// Add to local cache immediately
|
||||
if (!fileList.value.find(f => f.id === item.id)) {
|
||||
@@ -1065,6 +1177,17 @@ onMounted(() => {
|
||||
loadConversationConfig();
|
||||
loadChatModels();
|
||||
loadAgents();
|
||||
|
||||
// 从持久化恢复 fileId -> kbId,刷新后共享知识库文件可带 kb_id 拉取(仅保留当前仍选中的文件)
|
||||
const persisted = settingsStore.settings.selectedFileKbMap;
|
||||
const ids = settingsStore.settings.selectedFiles || [];
|
||||
if (persisted && typeof persisted === 'object' && ids.length > 0) {
|
||||
const next: Record<string, string> = {};
|
||||
ids.forEach((id: string) => {
|
||||
if (persisted[id]) next[id] = persisted[id];
|
||||
});
|
||||
fileIdToKbId.value = next;
|
||||
}
|
||||
|
||||
// 如果从知识库内部进入,自动选中该知识库
|
||||
const kbId = (route.params as any)?.kbId as string;
|
||||
@@ -1298,8 +1421,8 @@ const selectAgentMode = (mode: 'quick-answer' | 'smart-reasoning') => {
|
||||
showAgentModeSelector.value = false;
|
||||
}
|
||||
|
||||
// 选择智能体(新版)
|
||||
const handleSelectAgent = (agent: CustomAgent) => {
|
||||
// 选择智能体(新版);sourceTenantId 为共享智能体时传入
|
||||
const handleSelectAgent = (agent: CustomAgent, sourceTenantId?: string) => {
|
||||
// 根据智能体的 agent_mode 判断是否为 Agent 模式
|
||||
const isAgentType = agent.config?.agent_mode === 'smart-reasoning';
|
||||
|
||||
@@ -1317,27 +1440,23 @@ const handleSelectAgent = (agent: CustomAgent) => {
|
||||
return;
|
||||
}
|
||||
|
||||
selectedAgentId.value = agent.id;
|
||||
settingsStore.selectAgent(agent.id, sourceTenantId);
|
||||
settingsStore.toggleAgent(!!isAgentType);
|
||||
|
||||
// 同步智能体的配置状态(包括内置和自定义智能体)
|
||||
// 同步智能体的配置状态(含内置、自定义、共享智能体):模型、网络搜索、知识库由 watch 同步
|
||||
// 1. 同步网络搜索状态
|
||||
const agentWebSearch = agent.config?.web_search_enabled;
|
||||
if (agentWebSearch !== undefined) {
|
||||
// 智能体配置了网络搜索设置,同步到 store
|
||||
settingsStore.toggleWebSearch(agentWebSearch);
|
||||
} else if (agent.is_builtin) {
|
||||
// 如果是内置智能体且未配置网络搜索,不强制修改,保留当前用户设置
|
||||
// 或者可以考虑恢复默认值,视需求而定
|
||||
// 内置智能体未配置时保留当前用户设置
|
||||
}
|
||||
|
||||
// 2. 同步模型
|
||||
// 2. 同步模型(选中的对话模型随智能体切换,含共享智能体)
|
||||
const agentModel = agent.config?.model_id;
|
||||
if (agentModel) {
|
||||
if (agentModel && agentModel.trim() !== '') {
|
||||
selectedModelId.value = agentModel;
|
||||
} else if (agent.is_builtin) {
|
||||
// 如果是内置智能体且未配置特定模型,恢复为系统默认模型
|
||||
// 这样可以确保从专用模型切换回普通模式时,模型也切回通用模型
|
||||
} else {
|
||||
if (conversationConfig.value?.summary_model_id) {
|
||||
selectedModelId.value = conversationConfig.value.summary_model_id;
|
||||
}
|
||||
@@ -1672,6 +1791,7 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
:visible="showAgentModeSelector"
|
||||
:anchorEl="agentModeButtonRef"
|
||||
:currentAgentId="selectedAgentId"
|
||||
:agents="agents"
|
||||
@close="closeAgentModeSelector"
|
||||
@select="handleSelectAgent"
|
||||
/>
|
||||
@@ -1748,7 +1868,7 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
@click.stop="toggleModelSelector"
|
||||
>
|
||||
<span class="model-selector-name">
|
||||
{{ selectedModel?.name || $t('input.notConfigured') }}
|
||||
{{ selectedModelDisplayName }}
|
||||
</span>
|
||||
<svg
|
||||
width="12"
|
||||
@@ -1893,33 +2013,15 @@ const getImgSrc = (url: string) => {
|
||||
border: 1px solid transparent;
|
||||
color: var(--td-text-color-primary, #333);
|
||||
|
||||
/* KB - Document (Greenish tint) */
|
||||
&.kb-tag {
|
||||
background: rgba(16, 185, 129, 0.08);
|
||||
color: #059669;
|
||||
|
||||
.tag-icon {
|
||||
color: #10b981;
|
||||
}
|
||||
}
|
||||
|
||||
/* KB - FAQ (Blueish tint) */
|
||||
&.faq-tag {
|
||||
background: rgba(0, 82, 217, 0.08);
|
||||
color: #0052d9;
|
||||
|
||||
.tag-icon {
|
||||
color: #0052d9;
|
||||
}
|
||||
}
|
||||
|
||||
/* File (Orange tint) */
|
||||
/* 知识库 / 文件 - 无背景,与整体一致 */
|
||||
&.kb-tag,
|
||||
&.faq-tag,
|
||||
&.file-tag {
|
||||
background: rgba(237, 123, 47, 0.08);
|
||||
color: #e65100;
|
||||
background: transparent;
|
||||
color: var(--td-text-color-primary, #333);
|
||||
|
||||
.tag-icon {
|
||||
color: #ed7b2f;
|
||||
color: var(--td-text-color-secondary, #666);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,19 +18,15 @@
|
||||
@click="$emit('select', item)"
|
||||
@mouseenter="$emit('update:activeIndex', index)"
|
||||
>
|
||||
<div class="icon-wrap" :class="{ 'has-org': item.orgName }">
|
||||
<div class="icon-wrap">
|
||||
<div class="icon" :class="item.kbType === 'faq' ? 'faq-icon' : 'kb-icon'">
|
||||
<t-icon :name="item.kbType === 'faq' ? 'chat-bubble-help' : 'folder'" />
|
||||
</div>
|
||||
<span v-if="item.orgName" class="org-badge-wrap">
|
||||
<img src="@/assets/img/organization-green.svg" class="org-badge" alt="" aria-hidden="true" />
|
||||
</span>
|
||||
</div>
|
||||
<div class="item-main">
|
||||
<span class="name">{{ item.name }}</span>
|
||||
<span class="count">({{ item.count || 0 }})</span>
|
||||
</div>
|
||||
<span v-if="item.orgName" class="org-name">{{ item.orgName }}</span>
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="mention-detail-content">
|
||||
@@ -90,16 +86,12 @@
|
||||
@click="$emit('select', item)"
|
||||
@mouseenter="$emit('update:activeIndex', kbItems.length + index)"
|
||||
>
|
||||
<div class="icon-wrap" :class="{ 'has-org': item.orgName }">
|
||||
<div class="icon-wrap">
|
||||
<div class="icon file-icon">
|
||||
<t-icon name="file" />
|
||||
</div>
|
||||
<span v-if="item.orgName" class="org-badge-wrap">
|
||||
<img src="@/assets/img/organization-grey.svg" class="org-badge" alt="" aria-hidden="true" />
|
||||
</span>
|
||||
</div>
|
||||
<span class="name">{{ item.name }}</span>
|
||||
<span v-if="item.kbName" class="kb-name">{{ item.kbName }}</span>
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="mention-detail-content">
|
||||
@@ -158,6 +150,7 @@ import { useRouter } from 'vue-router';
|
||||
import { getKnowledgeBaseById } from '@/api/knowledge-base';
|
||||
import { getKnowledgeDetails } from '@/api/knowledge-base';
|
||||
import { useOrganizationStore } from '@/stores/organization';
|
||||
import { useSettingsStore } from '@/stores/settings';
|
||||
|
||||
type DetailState = { loading: boolean; error?: string; data?: any };
|
||||
|
||||
@@ -174,9 +167,17 @@ const emit = defineEmits(['select', 'update:activeIndex', 'loadMore']);
|
||||
|
||||
const router = useRouter();
|
||||
const orgStore = useOrganizationStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
const menuRef = ref<HTMLElement | null>(null);
|
||||
const detailCache = ref<Record<string, DetailState>>({});
|
||||
|
||||
// 共享智能体上下文:用于请求知识库/知识详情时带 agent_id,后端据此校验权限
|
||||
const agentIdForDetail = computed(() => {
|
||||
const sourceTenantId = settingsStore.selectedAgentSourceTenantId;
|
||||
const agentId = settingsStore.selectedAgentId;
|
||||
return sourceTenantId && agentId ? agentId : undefined;
|
||||
});
|
||||
|
||||
const kbItems = computed(() => props.items.filter(item => item.type === 'kb'));
|
||||
const fileItems = computed(() => props.items.filter(item => item.type === 'file'));
|
||||
|
||||
@@ -184,7 +185,8 @@ async function fetchKbDetail(item: { id: string }) {
|
||||
if (detailCache.value[item.id]?.data || detailCache.value[item.id]?.loading) return;
|
||||
detailCache.value = { ...detailCache.value, [item.id]: { loading: true } };
|
||||
try {
|
||||
const res: any = await getKnowledgeBaseById(item.id);
|
||||
const opts = agentIdForDetail.value ? { agent_id: agentIdForDetail.value } : undefined;
|
||||
const res: any = await getKnowledgeBaseById(item.id, opts);
|
||||
detailCache.value = { ...detailCache.value, [item.id]: { loading: false, data: res?.data ?? res } };
|
||||
} catch (e: any) {
|
||||
detailCache.value = { ...detailCache.value, [item.id]: { loading: false, error: e?.message || 'Failed to load' } };
|
||||
@@ -195,7 +197,8 @@ async function fetchFileDetail(item: { id: string }) {
|
||||
if (detailCache.value[item.id]?.data || detailCache.value[item.id]?.loading) return;
|
||||
detailCache.value = { ...detailCache.value, [item.id]: { loading: true } };
|
||||
try {
|
||||
const res: any = await getKnowledgeDetails(item.id);
|
||||
const opts = agentIdForDetail.value ? { agent_id: agentIdForDetail.value } : undefined;
|
||||
const res: any = await getKnowledgeDetails(item.id, opts);
|
||||
detailCache.value = { ...detailCache.value, [item.id]: { loading: false, data: res?.data ?? res } };
|
||||
} catch (e: any) {
|
||||
detailCache.value = { ...detailCache.value, [item.id]: { loading: false, error: e?.message || 'Failed to load' } };
|
||||
@@ -365,22 +368,12 @@ const scrollToItem = (index: number) => {
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
/* Document KB - Greenish */
|
||||
.kb-icon {
|
||||
background: rgba(16, 185, 129, 0.1);
|
||||
color: #10b981;
|
||||
}
|
||||
|
||||
/* FAQ KB - Blueish */
|
||||
.faq-icon {
|
||||
background: rgba(0, 82, 217, 0.1);
|
||||
color: #0052d9;
|
||||
}
|
||||
|
||||
/* File - Orange */
|
||||
/* 知识库 / 文件 - 无背景,与整体一致 */
|
||||
.kb-icon,
|
||||
.faq-icon,
|
||||
.file-icon {
|
||||
background: rgba(237, 123, 47, 0.1);
|
||||
color: #ed7b2f;
|
||||
background: transparent;
|
||||
color: var(--td-text-color-secondary, #666);
|
||||
}
|
||||
|
||||
.mention-item.active .icon {
|
||||
|
||||
@@ -42,13 +42,17 @@
|
||||
</t-tag>
|
||||
</div>
|
||||
<div class="org-option-meta">
|
||||
<span class="org-meta-item">
|
||||
<span class="org-meta-tag">
|
||||
<t-icon name="user" class="org-meta-icon org-meta-icon-user" />
|
||||
{{ org.member_count || 0 }} {{ $t('organization.members') }}
|
||||
{{ org.member_count ?? 0 }}
|
||||
</span>
|
||||
<span v-if="org.share_count !== undefined" class="org-meta-item">
|
||||
<span class="org-meta-tag">
|
||||
<img src="@/assets/img/zhishiku.svg" class="org-meta-icon org-meta-icon-kb" alt="" aria-hidden="true" />
|
||||
{{ org.share_count }} {{ $t('organization.share.sharedKBs') }}
|
||||
{{ org.share_count ?? 0 }}
|
||||
</span>
|
||||
<span class="org-meta-tag">
|
||||
<img src="@/assets/img/organization-grey.svg" class="org-meta-icon org-meta-icon-kb" alt="" aria-hidden="true" />
|
||||
{{ org.agent_share_count ?? 0 }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -422,15 +426,18 @@ function handleGoToOrgSettings(orgId: string) {
|
||||
.org-option-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
gap: 6px;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
|
||||
.org-meta-item {
|
||||
display: flex;
|
||||
.org-meta-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
padding: 0px 4px;
|
||||
background: #f0f0f0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.org-meta-icon {
|
||||
@@ -440,14 +447,12 @@ function handleGoToOrgSettings(orgId: string) {
|
||||
}
|
||||
|
||||
.org-meta-icon-user {
|
||||
font-size: 14px;
|
||||
margin-right: 2px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.org-meta-icon-kb {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
margin-right: 2px;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
opacity: 0.75;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user