feat: 添加智能体文件类型限制,内置数据分析师智能体
This commit is contained in:
@@ -26,6 +26,11 @@ export interface CustomAgentConfig {
|
||||
kb_selection_mode?: 'all' | 'selected' | 'none';
|
||||
knowledge_bases?: string[];
|
||||
|
||||
// ===== 文件类型限制 =====
|
||||
// 支持的文件类型(如 ["csv", "xlsx", "xls"])
|
||||
// 为空表示支持所有文件类型
|
||||
supported_file_types?: string[];
|
||||
|
||||
// ===== 网络搜索设置 =====
|
||||
web_search_enabled?: boolean;
|
||||
web_search_max_results?: number;
|
||||
@@ -85,7 +90,7 @@ export interface UpdateAgentRequest {
|
||||
config?: CustomAgentConfig;
|
||||
}
|
||||
|
||||
// 内置智能体 ID
|
||||
// 内置智能体 ID(常用的保留常量,便于代码引用)
|
||||
export const BUILTIN_QUICK_ANSWER_ID = 'builtin-quick-answer';
|
||||
export const BUILTIN_SMART_REASONING_ID = 'builtin-smart-reasoning';
|
||||
|
||||
@@ -98,12 +103,6 @@ export const BUILTIN_AGENT_NORMAL_ID = BUILTIN_QUICK_ANSWER_ID;
|
||||
// Deprecated: Use BUILTIN_SMART_REASONING_ID instead
|
||||
export const BUILTIN_AGENT_AGENT_ID = BUILTIN_SMART_REASONING_ID;
|
||||
|
||||
// 所有内置智能体 ID 列表(便于扩展)
|
||||
export const BUILTIN_AGENT_IDS = [
|
||||
BUILTIN_QUICK_ANSWER_ID,
|
||||
BUILTIN_SMART_REASONING_ID,
|
||||
] as const;
|
||||
|
||||
// 获取智能体列表(包括内置智能体)
|
||||
export function listAgents() {
|
||||
return get<{ data: CustomAgent[] }>('/api/v1/agents');
|
||||
@@ -134,9 +133,9 @@ export function copyAgent(id: string) {
|
||||
return post<{ data: CustomAgent }>(`/api/v1/agents/${id}/copy`);
|
||||
}
|
||||
|
||||
// 判断是否为内置智能体
|
||||
// 判断是否为内置智能体(通过 agent.is_builtin 字段或 ID 前缀判断)
|
||||
export function isBuiltinAgent(agentId: string): boolean {
|
||||
return (BUILTIN_AGENT_IDS as readonly string[]).includes(agentId);
|
||||
return agentId.startsWith('builtin-');
|
||||
}
|
||||
|
||||
// 占位符定义
|
||||
|
||||
@@ -232,6 +232,10 @@ export function getFAQImportProgress(taskId: string) {
|
||||
return get(`/api/v1/faq/import/progress/${taskId}`);
|
||||
}
|
||||
|
||||
export function searchKnowledge(keyword: string, offset = 0, limit = 20) {
|
||||
return get(`/api/v1/knowledge/search?keyword=${encodeURIComponent(keyword)}&offset=${offset}&limit=${limit}`);
|
||||
export function searchKnowledge(keyword: string, offset = 0, limit = 20, fileTypes?: string[]) {
|
||||
let url = `/api/v1/knowledge/search?keyword=${encodeURIComponent(keyword)}&offset=${offset}&limit=${limit}`;
|
||||
if (fileTypes && fileTypes.length > 0) {
|
||||
url += `&file_types=${encodeURIComponent(fileTypes.join(','))}`;
|
||||
}
|
||||
return get(url);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -617,6 +617,30 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 支持的文件类型(限制用户可选择的文件类型) -->
|
||||
<div v-if="hasKnowledgeBase" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>支持的文件类型</label>
|
||||
<p class="desc">限制可选择的文件类型,留空表示支持所有类型</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-select
|
||||
v-model="formData.config.supported_file_types"
|
||||
multiple
|
||||
placeholder="全部类型"
|
||||
:min-collapsed-num="3"
|
||||
clearable
|
||||
>
|
||||
<t-option
|
||||
v-for="ft in availableFileTypes"
|
||||
:key="ft.value"
|
||||
:value="ft.value"
|
||||
:label="ft.label"
|
||||
/>
|
||||
</t-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ReRank 模型(当配置了知识库时显示) -->
|
||||
<div v-if="needsRerankModel" class="setting-row">
|
||||
<div class="setting-info">
|
||||
@@ -978,6 +1002,9 @@ const defaultTemperature = ref(0.7);
|
||||
// 知识库相关工具列表
|
||||
const knowledgeBaseTools = ['grep_chunks', 'knowledge_search', 'list_knowledge_chunks', 'query_knowledge_graph', 'get_document_info', 'database_query'];
|
||||
|
||||
// 初始化标志,防止初始化时触发 watch 自动添加工具
|
||||
const isInitializing = ref(false);
|
||||
|
||||
// 知识库选择模式:all=全部, selected=指定, none=不使用
|
||||
const kbSelectionMode = ref<'all' | 'selected' | 'none'>('none');
|
||||
|
||||
@@ -1022,6 +1049,17 @@ const availableTools = computed(() => {
|
||||
}));
|
||||
});
|
||||
|
||||
// 可用文件类型列表
|
||||
const availableFileTypes = [
|
||||
{ value: 'pdf', label: 'PDF', description: 'PDF 文档' },
|
||||
{ value: 'docx', label: 'Word', description: 'Word 文档 (.docx/.doc)' },
|
||||
{ value: 'txt', label: '文本', description: '纯文本文件 (.txt)' },
|
||||
{ value: 'md', label: 'Markdown', description: 'Markdown 文档' },
|
||||
{ value: 'csv', label: 'CSV', description: '逗号分隔值文件' },
|
||||
{ value: 'xlsx', label: 'Excel', description: 'Excel 表格 (.xlsx/.xls)' },
|
||||
{ value: 'jpg', label: '图片', description: '图片文件 (.jpg/.jpeg/.png)' },
|
||||
];
|
||||
|
||||
// 占位符相关 - 从 API 获取
|
||||
const placeholderData = ref<{
|
||||
system_prompt: PlaceholderDefinition[];
|
||||
@@ -1145,6 +1183,8 @@ const defaultFormData = {
|
||||
// 知识库设置
|
||||
kb_selection_mode: 'none' as 'all' | 'selected' | 'none',
|
||||
knowledge_bases: [] as string[],
|
||||
// 文件类型限制
|
||||
supported_file_types: [] as string[],
|
||||
// FAQ 策略设置
|
||||
faq_priority_enabled: true, // 是否启用 FAQ 优先策略
|
||||
faq_direct_answer_threshold: 0.9, // FAQ 直接回答阈值(相似度高于此值直接使用 FAQ 答案)
|
||||
@@ -1227,6 +1267,7 @@ watch(() => props.visible, async (val) => {
|
||||
if (!agentData.config.knowledge_bases) agentData.config.knowledge_bases = [];
|
||||
if (!agentData.config.allowed_tools) agentData.config.allowed_tools = [];
|
||||
if (!agentData.config.mcp_services) agentData.config.mcp_services = [];
|
||||
if (!agentData.config.supported_file_types) agentData.config.supported_file_types = [];
|
||||
|
||||
// 兼容旧数据:如果没有 agent_mode 字段,根据 allowed_tools 推断
|
||||
if (!agentData.config.agent_mode) {
|
||||
@@ -1234,10 +1275,16 @@ watch(() => props.visible, async (val) => {
|
||||
agentData.config.agent_mode = isAgent ? 'smart-reasoning' : 'quick-answer';
|
||||
}
|
||||
|
||||
// 设置初始化标志,防止 watch 自动添加工具
|
||||
isInitializing.value = true;
|
||||
formData.value = agentData;
|
||||
// 初始化知识库选择模式
|
||||
initKbSelectionMode();
|
||||
initMcpSelectionMode();
|
||||
// 初始化完成后重置标志
|
||||
nextTick(() => {
|
||||
isInitializing.value = false;
|
||||
});
|
||||
// 内置智能体:如果提示词为空,填入系统默认值
|
||||
if (agentData.is_builtin) {
|
||||
fillBuiltinAgentDefaults();
|
||||
@@ -1390,7 +1437,8 @@ watch(hasKnowledgeBase, (hasKB, oldHasKB) => {
|
||||
currentSection.value = 'basic';
|
||||
}
|
||||
|
||||
if (!isAgentMode.value) return; // 只在Agent模式下处理工具
|
||||
// 初始化期间或非 Agent 模式下不自动调整工具
|
||||
if (isInitializing.value || !isAgentMode.value) return;
|
||||
|
||||
if (hasKB && !oldHasKB) {
|
||||
// 从无知识库变为有知识库,自动添加知识库相关工具
|
||||
|
||||
Reference in New Issue
Block a user