feat: 添加智能体文件类型限制,内置数据分析师智能体

This commit is contained in:
wizardchen
2025-12-31 18:18:22 +08:00
committed by lyingbug
parent 884153aeb8
commit d72b6997cb
10 changed files with 290 additions and 56 deletions
+53 -32
View File
@@ -33,9 +33,16 @@
:class="{ 'selected': currentAgentId === agent.id }"
@click="selectAgent(agent)"
>
<div class="builtin-icon" :class="agent.config?.agent_mode === 'smart-reasoning' ? 'agent' : 'normal'">
<!-- 快速回答和智能推理使用图标,其他内置智能体使用 avatar -->
<div v-if="agent.id === BUILTIN_QUICK_ANSWER_ID || agent.id === BUILTIN_SMART_REASONING_ID"
class="builtin-icon"
:class="agent.config?.agent_mode === 'smart-reasoning' ? 'agent' : 'normal'">
<TIcon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'" size="14px" />
</div>
<div v-else-if="agent.avatar" class="builtin-avatar">{{ agent.avatar }}</div>
<div v-else class="builtin-icon normal">
<TIcon name="app" size="14px" />
</div>
<span class="agent-option-name">{{ agent.name }}</span>
<svg
v-if="currentAgentId === agent.id"
@@ -51,9 +58,16 @@
<template #content>
<div class="agent-tooltip-content">
<div class="agent-tooltip-header">
<div class="builtin-icon" :class="agent.config?.agent_mode === 'smart-reasoning' ? 'agent' : 'normal'">
<!-- 快速回答和智能推理使用图标,其他内置智能体使用 avatar -->
<div v-if="agent.id === BUILTIN_QUICK_ANSWER_ID || agent.id === BUILTIN_SMART_REASONING_ID"
class="builtin-icon"
:class="agent.config?.agent_mode === 'smart-reasoning' ? 'agent' : 'normal'">
<TIcon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'" size="14px" />
</div>
<div v-else-if="agent.avatar" class="builtin-avatar">{{ agent.avatar }}</div>
<div v-else class="builtin-icon normal">
<TIcon name="app" size="14px" />
</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>
@@ -170,40 +184,29 @@ const emit = defineEmits<{
const agents = ref<CustomAgent[]>([]);
const dropdownStyle = ref<Record<string, string>>({});
// 内置智能体
// 内置智能体(从 API 获取,对特定 ID 使用本地化名称)
const builtinAgents = computed(() => {
const defaults = [
{
id: BUILTIN_QUICK_ANSWER_ID,
name: t('input.normalMode'),
description: t('input.normalModeDesc'),
is_builtin: true,
config: { agent_mode: 'quick-answer' as const }
},
{
id: BUILTIN_SMART_REASONING_ID,
name: t('input.agentMode'),
description: t('input.agentModeDesc'),
is_builtin: true,
config: { agent_mode: 'smart-reasoning' as const }
}
];
return defaults.map(def => {
const apiAgent = agents.value.find(a => a.id === def.id);
if (apiAgent) {
// 从 API 获取的内置智能体
const apiBuiltins = agents.value.filter(a => a.is_builtin);
// 对特定内置智能体使用本地化名称和描述
return apiBuiltins.map(agent => {
if (agent.id === BUILTIN_QUICK_ANSWER_ID) {
return {
...apiAgent,
name: def.name,
description: def.description,
config: {
...(apiAgent.config || {}),
agent_mode: def.config.agent_mode
}
...agent,
name: t('input.normalMode'),
description: t('input.normalModeDesc'),
};
} else if (agent.id === BUILTIN_SMART_REASONING_ID) {
return {
...agent,
name: t('input.agentMode'),
description: t('input.agentModeDesc'),
};
}
return def;
}) as CustomAgent[];
// 其他内置智能体使用 API 返回的名称和描述
return agent;
});
});
// 自定义智能体
@@ -466,6 +469,18 @@ onMounted(() => {
}
}
.builtin-avatar {
display: flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
border-radius: 6px;
flex-shrink: 0;
font-size: 16px;
background: var(--td-bg-color-secondarycontainer, #f5f5f5);
}
.check-icon {
width: 14px;
height: 14px;
@@ -491,6 +506,12 @@ onMounted(() => {
width: 28px;
height: 28px;
}
.builtin-avatar {
width: 28px;
height: 28px;
font-size: 18px;
}
}
.agent-tooltip-title {
+13 -2
View File
@@ -129,6 +129,12 @@ const agentModelId = computed(() => {
return currentAgentConfig.value?.model_id || null;
});
// 智能体支持的文件类型(空数组表示支持所有类型)
const agentSupportedFileTypes = computed(() => {
if (!hasAgentConfig.value) return [];
return currentAgentConfig.value?.supported_file_types || [];
});
// 模型选择是否被智能体锁定 - 已移除锁定逻辑,允许用户自由切换模型
const isModelLockedByAgent = computed(() => {
return false;
@@ -355,9 +361,12 @@ const loadConversationConfig = async () => {
const response = await getConversationConfig();
conversationConfig.value = response.data;
const modelId = response.data?.summary_model_id || '';
// 保留当前已选择的模型(如果有),避免覆盖从其他页面传递的模型选择
const currentSelectedModel = settingsStore.conversationModels.selectedChatModelId;
settingsStore.updateConversationModels({
summaryModelId: modelId,
selectedChatModelId: modelId,
selectedChatModelId: currentSelectedModel || modelId, // 优先保留当前选择
rerankModelId: response.data?.rerank_model_id || '',
});
if (!selectedModelId.value) {
@@ -615,7 +624,9 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) =>
if (shouldLoadFiles) {
mentionLoading.value = true;
try {
const res: any = await searchKnowledge(q || '', mentionOffset.value, MENTION_PAGE_SIZE);
// 将文件类型过滤传递给后端
const fileTypesParam = agentSupportedFileTypes.value.length > 0 ? agentSupportedFileTypes.value : undefined;
const res: any = await searchKnowledge(q || '', mentionOffset.value, MENTION_PAGE_SIZE, fileTypesParam);
console.log('[Mention] searchKnowledge response:', res);
if (res.data && Array.isArray(res.data)) {
let files = res.data;