From 0ca947981aab284bb57beb53c2d625e44a8f9393 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Fri, 26 Dec 2025 21:31:02 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=B0=83=E6=95=B4=E6=99=BA?= =?UTF-8?q?=E8=83=BD=E4=BD=93=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=A2=9E=E5=BC=BA?= =?UTF-8?q?=E6=99=BA=E8=83=BD=E4=BD=93=E9=80=89=E6=8B=A9=E4=B8=8E=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.yaml | 21 +- config/prompt_templates/fallback.yaml | 2 +- config/prompt_templates/rewrite_user.yaml | 17 +- frontend/src/api/agent/index.ts | 64 +- frontend/src/components/AgentAvatar.vue | 13 +- frontend/src/components/AgentSelector.vue | 30 +- frontend/src/components/Input-field.vue | 440 ++++--- frontend/src/components/UserMenu.vue | 4 - frontend/src/i18n/locales/en-US.ts | 22 +- frontend/src/i18n/locales/zh-CN.ts | 20 +- frontend/src/stores/settings.ts | 21 +- frontend/src/views/agent/AgentEditorModal.vue | 1084 +++++++++++++---- frontend/src/views/agent/AgentList.vue | 268 ++-- .../src/views/knowledge/KnowledgeBaseList.vue | 203 ++- frontend/src/views/settings/Settings.vue | 17 - internal/agent/prompts.go | 30 +- .../application/repository/custom_agent.go | 4 +- internal/application/service/agent_service.go | 56 +- .../service/chat_pipline/common.go | 9 +- .../service/chat_pipline/load_history.go | 126 ++ .../service/chat_pipline/rewrite.go | 84 +- internal/application/service/custom_agent.go | 142 ++- internal/application/service/knowledge.go | 16 +- internal/application/service/session.go | 40 +- internal/container/container.go | 1 + internal/handler/custom_agent.go | 85 +- internal/handler/session/qa.go | 4 +- internal/router/router.go | 4 + internal/types/agent.go | 3 + internal/types/chat_manage.go | 8 +- internal/types/custom_agent.go | 156 ++- internal/types/interfaces/custom_agent.go | 12 +- internal/types/placeholder.go | 165 +++ internal/types/tenant.go | 6 +- .../versioned/000006_custom_agents.down.sql | 3 +- .../versioned/000006_custom_agents.up.sql | 157 ++- 36 files changed, 2421 insertions(+), 916 deletions(-) create mode 100644 internal/application/service/chat_pipline/load_history.go create mode 100644 internal/types/placeholder.go diff --git a/config/config.yaml b/config/config.yaml index 693a7064..7cdb6e31 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -23,7 +23,7 @@ conversation: - 使用礼貌、专业的语气 ## 用户的问题是: - {{.Query}} + {{query}} enable_rewrite: true enable_query_expansion: true enable_rerank: true @@ -82,15 +82,10 @@ conversation: 改写后: 国外手机号是否可以注册微信账号 rewrite_prompt_user: | ## 历史对话背景 - {{range .Conversation}} - ------BEGIN------ - 用户的问题是:{{.Query}} - 助手的回答是:{{.Answer}} - ------END------ - {{end}} + {{conversation}} ## 需要改写的用户问题 - {{.Query}} + {{query}} ## 改写后的问题 keywords_extraction_prompt: | @@ -134,7 +129,7 @@ conversation: Output: iPhone, 连接WiFi, 使用iPhone连接WiFi # Real Data - USER: {{.Query}} + USER: {{query}} keywords_extraction_prompt_user: | Output: @@ -483,11 +478,11 @@ conversation: generate_questions_prompt: | 你是一个专业的问题生成助手。你的任务是根据给定的【主要内容】生成用户可能会问的相关问题。 - {{.Context}} + {{context}} ## 主要内容(请基于此内容生成问题) - 文档名称:{{.DocName}} + 文档名称:{{doc_name}} 文档内容: - {{.Content}} + {{content}} ## 核心要求 - 生成的问题必须与【主要内容】直接相关 @@ -496,7 +491,7 @@ conversation: - 问题应该是用户在实际场景中可能会提出的自然问题 - 问题应该多样化,覆盖内容的不同方面 - 每个问题应该简洁明了,长度控制在30字以内 - - 生成的问题数量为 {{.QuestionCount}} 个 + - 生成的问题数量为 {{question_count}} 个 ## 问题类型建议 - 定义类:什么是...?...是什么? diff --git a/config/prompt_templates/fallback.yaml b/config/prompt_templates/fallback.yaml index e1902d11..5f0e722a 100644 --- a/config/prompt_templates/fallback.yaml +++ b/config/prompt_templates/fallback.yaml @@ -44,4 +44,4 @@ templates: 2. 如果问题涉及特定领域或需要最新信息,建议用户查阅官方资料 3. 保持回答的准确性和客观性 - 用户问题:{{.Query}} + 用户问题:{{query}} diff --git a/config/prompt_templates/rewrite_user.yaml b/config/prompt_templates/rewrite_user.yaml index 54e0f994..8605c1af 100644 --- a/config/prompt_templates/rewrite_user.yaml +++ b/config/prompt_templates/rewrite_user.yaml @@ -5,15 +5,10 @@ templates: description: "标准的改写用户提示词格式" content: | ## 历史对话背景 - {{range .Conversation}} - ------BEGIN------ - 用户的问题是:{{.Query}} - 助手的回答是:{{.Answer}} - ------END------ - {{end}} + {{conversation}} ## 需要改写的用户问题 - {{.Query}} + {{query}} ## 改写后的问题 @@ -24,14 +19,10 @@ templates: ## 历史对话背景 以下是用户与助手的对话历史,请仔细阅读以理解上下文: - {{range .Conversation}} - 【用户】{{.Query}} - 【助手】{{.Answer}} - - {{end}} + {{conversation}} ## 当前用户问题 - {{.Query}} + {{query}} ## 任务要求 请根据以上对话历史,将当前问题改写为一个独立、完整、可以脱离上下文理解的问题。 diff --git a/frontend/src/api/agent/index.ts b/frontend/src/api/agent/index.ts index 43987153..927daa63 100644 --- a/frontend/src/api/agent/index.ts +++ b/frontend/src/api/agent/index.ts @@ -1,12 +1,9 @@ import { get, post, put, del } from "../../utils/request"; -// 智能体类型 -export type CustomAgentType = 'normal' | 'agent' | 'custom'; - // 智能体配置 export interface CustomAgentConfig { // ===== 基础设置 ===== - agent_mode?: 'normal' | 'agent'; // 运行模式:normal=RAG模式, agent=ReAct Agent模式 + agent_mode?: 'quick-answer' | 'smart-reasoning'; // 运行模式:quick-answer=RAG模式, smart-reasoning=ReAct Agent模式 system_prompt?: string; // 系统提示词(普通模式,或Agent模式网络搜索关闭时) system_prompt_web_enabled?: string; // Agent模式网络搜索开启时的系统提示词 context_template?: string; // 上下文模板(普通模式) @@ -21,15 +18,14 @@ export interface CustomAgentConfig { max_iterations?: number; // 最大迭代次数 allowed_tools?: string[]; // 允许的工具 reflection_enabled?: boolean; // 是否启用反思 + // MCP服务选择模式:all=全部启用的MCP服务, selected=指定服务, none=不使用MCP + mcp_selection_mode?: 'all' | 'selected' | 'none'; + mcp_services?: string[]; // 选择的MCP服务ID列表 // ===== 知识库设置 ===== // 知识库选择模式:all=全部知识库, selected=指定知识库, none=不使用知识库 kb_selection_mode?: 'all' | 'selected' | 'none'; knowledge_bases?: string[]; - // 当没有配置知识库时,是否允许用户自由选择知识库 - // true (默认): 用户可以自由选择任意知识库 - // false: 禁用知识库选择功能 - allow_user_kb_selection?: boolean; // ===== 网络搜索设置 ===== web_search_enabled?: boolean; @@ -67,7 +63,6 @@ export interface CustomAgent { description?: string; avatar?: string; is_builtin: boolean; - type: CustomAgentType; tenant_id?: number; created_by?: string; config: CustomAgentConfig; @@ -80,7 +75,6 @@ export interface CreateAgentRequest { name: string; description?: string; avatar?: string; - type?: CustomAgentType; config?: CustomAgentConfig; } @@ -89,13 +83,27 @@ export interface UpdateAgentRequest { name: string; description?: string; avatar?: string; - type?: CustomAgentType; config?: CustomAgentConfig; } // 内置智能体 ID -export const BUILTIN_AGENT_NORMAL_ID = 'builtin-normal'; -export const BUILTIN_AGENT_AGENT_ID = 'builtin-agent'; +export const BUILTIN_QUICK_ANSWER_ID = 'builtin-quick-answer'; +export const BUILTIN_SMART_REASONING_ID = 'builtin-smart-reasoning'; + +// AgentMode 常量 +export const AGENT_MODE_QUICK_ANSWER = 'quick-answer'; +export const AGENT_MODE_SMART_REASONING = 'smart-reasoning'; + +// Deprecated: Use BUILTIN_QUICK_ANSWER_ID instead +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() { @@ -122,7 +130,35 @@ export function deleteAgent(id: string) { return del<{ success: boolean }>(`/api/v1/agents/${id}`); } +// 复制智能体 +export function copyAgent(id: string) { + return post<{ data: CustomAgent }>(`/api/v1/agents/${id}/copy`); +} + // 判断是否为内置智能体 export function isBuiltinAgent(agentId: string): boolean { - return agentId === BUILTIN_AGENT_NORMAL_ID || agentId === BUILTIN_AGENT_AGENT_ID; + return (BUILTIN_AGENT_IDS as readonly string[]).includes(agentId); +} + +// 占位符定义 +export interface PlaceholderDefinition { + name: string; + label: string; + description: string; +} + +// 占位符响应 +export interface PlaceholdersResponse { + all: PlaceholderDefinition[]; + system_prompt: PlaceholderDefinition[]; + agent_system_prompt: PlaceholderDefinition[]; + context_template: PlaceholderDefinition[]; + rewrite_system_prompt: PlaceholderDefinition[]; + rewrite_prompt: PlaceholderDefinition[]; + fallback_prompt: PlaceholderDefinition[]; +} + +// 获取占位符定义 +export function getPlaceholders() { + return get<{ data: PlaceholdersResponse }>('/api/v1/agents/placeholders'); } diff --git a/frontend/src/components/AgentAvatar.vue b/frontend/src/components/AgentAvatar.vue index 570e5181..af91eb24 100644 --- a/frontend/src/components/AgentAvatar.vue +++ b/frontend/src/components/AgentAvatar.vue @@ -110,12 +110,17 @@ const letterStyle = computed(() => { overflow: hidden; &.agent-avatar-small { - width: 24px; - height: 24px; - border-radius: 6px; + width: 22px; + height: 22px; + border-radius: 5px; + box-shadow: none; .agent-avatar-letter { - font-size: 12px; + font-size: 11px; + } + + .agent-sparkles { + display: none; } } diff --git a/frontend/src/components/AgentSelector.vue b/frontend/src/components/AgentSelector.vue index e8d6701f..701da0ae 100644 --- a/frontend/src/components/AgentSelector.vue +++ b/frontend/src/components/AgentSelector.vue @@ -32,8 +32,8 @@ :class="{ 'selected': currentAgentId === agent.id }" @click="selectAgent(agent)" > -
- +
+
{{ agent.name }} >({}); const builtinAgents = computed(() => { return [ { - id: 'builtin-normal', + id: BUILTIN_QUICK_ANSWER_ID, name: t('input.normalMode'), description: t('input.normalModeDesc'), - type: 'normal', - is_builtin: true + is_builtin: true, + config: { agent_mode: 'quick-answer' as const } }, { - id: 'builtin-agent', + id: BUILTIN_SMART_REASONING_ID, name: t('input.agentMode'), description: t('input.agentModeDesc'), - type: 'agent', - is_builtin: true + is_builtin: true, + config: { agent_mode: 'smart-reasoning' as const } } ] as CustomAgent[]; }); @@ -143,9 +143,9 @@ const customAgents = computed(() => { const getAgentCapabilities = (agent: CustomAgent): string => { // 内置智能体 if (agent.is_builtin) { - if (agent.type === 'normal') { + if (agent.config?.agent_mode === 'quick-answer') { return t('agent.capabilities.normal'); - } else if (agent.type === 'agent') { + } else if (agent.config?.agent_mode === 'smart-reasoning') { return t('agent.capabilities.agent'); } return ''; @@ -158,10 +158,12 @@ const getAgentCapabilities = (agent: CustomAgent): string => { if (config.model_id) { capabilities.push(t('agent.capabilities.modelSpecified')); } - if (config.knowledge_bases && config.knowledge_bases.length > 0) { - capabilities.push(t('agent.capabilities.kbCount', { count: config.knowledge_bases.length })); - } else if (config.allow_user_kb_selection === false) { + if (config.kb_selection_mode === 'none') { capabilities.push(t('agent.capabilities.kbDisabled')); + } else if (config.knowledge_bases && config.knowledge_bases.length > 0) { + capabilities.push(t('agent.capabilities.kbCount', { count: config.knowledge_bases.length })); + } else if (config.kb_selection_mode === 'all') { + capabilities.push(t('agent.capabilities.kbAll')); } if (config.rerank_model_id) { capabilities.push(t('agent.capabilities.rerankSpecified')); diff --git a/frontend/src/components/Input-field.vue b/frontend/src/components/Input-field.vue index 739b9027..5d6316f5 100644 --- a/frontend/src/components/Input-field.vue +++ b/frontend/src/components/Input-field.vue @@ -12,7 +12,7 @@ import MentionSelector from './MentionSelector.vue'; import AgentSelector from './AgentSelector.vue'; import { getCaretCoordinates } from '@/utils/caret'; import { listModels, type ModelConfig } from '@/api/model'; -import { listAgents, type CustomAgent } from '@/api/agent'; +import { listAgents, type CustomAgent, BUILTIN_QUICK_ANSWER_ID, BUILTIN_SMART_REASONING_ID } from '@/api/agent'; import { getTenantWebSearchConfig } from '@/api/web-search'; import { getConversationConfig, updateConversationConfig, type ConversationConfig } from '@/api/system'; import { useI18n } from 'vue-i18n'; @@ -31,80 +31,92 @@ const agentModeDropdownStyle = ref>({}); // 智能体相关状态 const agents = ref([]); const selectedAgentId = computed({ - get: () => settingsStore.selectedAgentId || 'builtin-normal', + get: () => settingsStore.selectedAgentId || BUILTIN_QUICK_ANSWER_ID, set: (val: string) => settingsStore.selectAgent(val) }); const selectedAgent = computed(() => { return agents.value.find(a => a.id === selectedAgentId.value) || { - id: 'builtin-normal', + id: BUILTIN_QUICK_ANSWER_ID, name: t('input.normalMode'), - type: 'normal', - is_builtin: true + is_builtin: true, + config: { agent_mode: 'quick-answer' as const } } as CustomAgent; }); // 判断是否为自定义智能体(非内置) const isCustomAgent = computed(() => { const agent = selectedAgent.value; - return agent && !agent.is_builtin && agent.type === 'custom'; + return agent && !agent.is_builtin; +}); + +// 判断是否有智能体配置(包括内置智能体) +const hasAgentConfig = computed(() => { + const agent = selectedAgent.value; + // 内置智能体需要从 agents 列表中获取实际配置 + if (agent?.is_builtin) { + const builtinAgent = agents.value.find(a => a.id === agent.id); + return !!builtinAgent?.config; + } + return !!agent?.config; +}); + +// 获取当前智能体的实际配置(内置智能体从 agents 列表获取) +const currentAgentConfig = computed(() => { + const agent = selectedAgent.value; + if (agent?.is_builtin) { + const builtinAgent = agents.value.find(a => a.id === agent.id); + return builtinAgent?.config || {}; + } + return agent?.config || {}; }); // 智能体预配置的知识库 IDs const agentKnowledgeBases = computed(() => { - if (!isCustomAgent.value) return []; - return selectedAgent.value?.config?.knowledge_bases || []; + if (!hasAgentConfig.value) return []; + return currentAgentConfig.value?.knowledge_bases || []; }); // 智能体的知识库选择模式 const agentKBSelectionMode = computed(() => { - if (!isCustomAgent.value) return null; // null 表示不受智能体控制 - return selectedAgent.value?.config?.kb_selection_mode || 'none'; + if (!hasAgentConfig.value) return null; // null 表示不受智能体控制 + return currentAgentConfig.value?.kb_selection_mode || 'all'; }); // 智能体是否启用了网络搜索 const agentWebSearchEnabled = computed(() => { - if (!isCustomAgent.value) return null; // null 表示不受智能体控制 - return selectedAgent.value?.config?.web_search_enabled ?? false; + if (!hasAgentConfig.value) return null; // null 表示不受智能体控制 + return currentAgentConfig.value?.web_search_enabled ?? true; }); -// 网络搜索是否被智能体禁用(只读状态) +// 网络搜索是否被智能体禁用(只读状态)- 只有明确设置为 false 时才禁用 const isWebSearchDisabledByAgent = computed(() => { - return isCustomAgent.value && agentWebSearchEnabled.value === false; -}); - -// 网络搜索是否被智能体强制启用 -const isWebSearchForcedByAgent = computed(() => { - return isCustomAgent.value && agentWebSearchEnabled.value === true; + return hasAgentConfig.value && agentWebSearchEnabled.value === false; }); // 知识库选择是否被智能体锁定 // 1. 如果智能体配置了 kb_selection_mode = 'none' → 完全禁用知识库 -// 2. 如果智能体配置了 kb_selection_mode = 'selected' 且 allow_user_kb_selection=false → 锁定到指定知识库 -// 3. 如果智能体配置了 kb_selection_mode = 'all' 且 allow_user_kb_selection=false → 锁定到全部知识库(但不允许用户选择) +// 其他情况用户都可以在允许的范围内通过 @ 选择知识库 const isKnowledgeBaseLockedByAgent = computed(() => { - if (!isCustomAgent.value) return false; - // 如果禁用了知识库,返回 true(锁定状态) - if (agentKBSelectionMode.value === 'none') return true; - // 如果不允许用户选择知识库,返回 true - const allowUserKBSelection = selectedAgent.value?.config?.allow_user_kb_selection; - return allowUserKBSelection === false; + if (!hasAgentConfig.value) return false; + // 只有禁用了知识库才锁定 + return agentKBSelectionMode.value === 'none'; }); // 知识库是否被智能体完全禁用(kb_selection_mode = 'none') const isKnowledgeBaseDisabledByAgent = computed(() => { - if (!isCustomAgent.value) return false; + if (!hasAgentConfig.value) return false; return agentKBSelectionMode.value === 'none'; }); // 智能体配置的模型 ID const agentModelId = computed(() => { - if (!isCustomAgent.value) return null; - return selectedAgent.value?.config?.model_id || null; + if (!hasAgentConfig.value) return null; + return currentAgentConfig.value?.model_id || null; }); // 模型选择是否被智能体锁定 const isModelLockedByAgent = computed(() => { - return isCustomAgent.value && !!agentModelId.value; + return hasAgentConfig.value && !!agentModelId.value; }); // Mention related state @@ -566,8 +578,8 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) => // 获取可选的知识库列表 let availableKbs = knowledgeBases.value; - // 如果是自定义智能体,根据 kb_selection_mode 过滤 - if (isCustomAgent.value) { + // 如果智能体有配置,根据 kb_selection_mode 过滤 + if (hasAgentConfig.value) { const kbMode = agentKBSelectionMode.value; if (kbMode === 'none') { // 不使用知识库,不显示任何知识库 @@ -596,7 +608,7 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) => // Fetch Files from API // 如果智能体禁用了知识库,也不显示文件 let fileItems: any[] = []; - const shouldLoadFiles = !isCustomAgent.value || agentKBSelectionMode.value !== 'none'; + const shouldLoadFiles = !hasAgentConfig.value || agentKBSelectionMode.value !== 'none'; if (shouldLoadFiles) { mentionLoading.value = true; @@ -606,8 +618,8 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) => if (res.data && Array.isArray(res.data)) { let files = res.data; - // 如果是自定义智能体且 kb_selection_mode === 'selected',只显示指定知识库中的文件 - if (isCustomAgent.value && agentKBSelectionMode.value === 'selected') { + // 如果智能体配置了 kb_selection_mode === 'selected',只显示指定知识库中的文件 + if (hasAgentConfig.value && agentKBSelectionMode.value === 'selected') { const configuredKbIds = agentKnowledgeBases.value; files = files.filter((f: any) => configuredKbIds.includes(f.knowledge_base_id)); } @@ -1136,18 +1148,24 @@ const toggleAgentModeSelector = () => { } } -const selectAgentMode = (mode: 'normal' | 'agent') => { - if (mode === 'agent' && !settingsStore.isAgentReady) { - toggleAgentMode(); - showAgentModeSelector.value = false; - return; +const selectAgentMode = (mode: 'quick-answer' | 'smart-reasoning') => { + const builtinAgentId = mode === 'smart-reasoning' ? BUILTIN_SMART_REASONING_ID : BUILTIN_QUICK_ANSWER_ID; + const builtinAgent = agents.value.find(a => a.id === builtinAgentId); + + if (builtinAgent) { + const notReadyReasons = getBuiltinAgentNotReadyReasons(builtinAgent, mode === 'smart-reasoning'); + if (notReadyReasons.length > 0) { + showBuiltinAgentNotReadyMessage(mode, notReadyReasons); + showAgentModeSelector.value = false; + return; + } } - const shouldEnableAgent = mode === 'agent'; + const shouldEnableAgent = mode === 'smart-reasoning'; if (shouldEnableAgent !== isAgentEnabled.value) { settingsStore.toggleAgent(shouldEnableAgent); // 同时更新选中的智能体 - settingsStore.selectAgent(shouldEnableAgent ? 'builtin-agent' : 'builtin-normal'); + settingsStore.selectAgent(shouldEnableAgent ? BUILTIN_SMART_REASONING_ID : BUILTIN_QUICK_ANSWER_ID); MessagePlugin.success(shouldEnableAgent ? t('input.messages.agentSwitchedOn') : t('input.messages.agentSwitchedOff')); } showAgentModeSelector.value = false; @@ -1155,21 +1173,36 @@ const selectAgentMode = (mode: 'normal' | 'agent') => { // 选择智能体(新版) const handleSelectAgent = (agent: CustomAgent) => { - selectedAgentId.value = agent.id; + // 根据智能体的 agent_mode 判断是否为 Agent 模式 + const isAgentType = agent.config?.agent_mode === 'smart-reasoning'; - // 根据智能体类型切换 Agent 模式 - const isAgentType = agent.type === 'agent' || (agent.type === 'custom' && (agent.config?.max_iterations ?? 0) > 1); - - if (isAgentType && !settingsStore.isAgentReady) { - // Agent 模式未就绪,显示提示 - toggleAgentMode(); - return; + // 内置智能体检查 - 从实际的智能体配置来判断 + if (agent.is_builtin) { + // 从 agents 列表中获取实际的内置智能体数据 + const builtinAgent = agents.value.find(a => a.id === agent.id); + if (builtinAgent) { + const notReadyReasons = getBuiltinAgentNotReadyReasons(builtinAgent, isAgentType); + if (notReadyReasons.length > 0) { + showBuiltinAgentNotReadyMessage(isAgentType ? 'smart-reasoning' : 'quick-answer', notReadyReasons); + return; + } + } } + // 自定义智能体检查 + if (!agent.is_builtin) { + const notReadyReasons = getCustomAgentNotReadyReasons(agent); + if (notReadyReasons.length > 0) { + showCustomAgentNotReadyMessage(agent, notReadyReasons); + return; + } + } + + selectedAgentId.value = agent.id; settingsStore.toggleAgent(!!isAgentType); // 如果是自定义智能体,同步网络搜索状态和模型 - if (!agent.is_builtin && agent.type === 'custom') { + if (!agent.is_builtin) { const agentWebSearch = agent.config?.web_search_enabled; if (agentWebSearch !== undefined) { // 智能体配置了网络搜索设置,同步到 store @@ -1250,75 +1283,125 @@ const handleGoToWebSearchSettings = () => { } }; -const handleGoToAgentSettings = () => { - // 使用 uiStore 打开设置并跳转到 agent 部分 - uiStore.openSettings('agent'); - // 如果当前不在设置页面,导航到设置页面 - if (route.path !== '/platform/settings') { - router.push('/platform/settings'); +const handleGoToAgentSettings = (section?: string) => { + // 跳转到智能体列表页并打开编辑弹窗 + if (selectedAgent.value && !selectedAgent.value.is_builtin) { + const query: Record = { edit: selectedAgent.value.id }; + if (section) { + query.section = section; + } + router.push({ path: '/platform/agents', query }); + } else { + router.push('/platform/agents'); } -} +}; -// 获取 Agent 不就绪的原因 -const getAgentNotReadyReasons = (): string[] => { +// 获取内置智能体不就绪的原因 +const getBuiltinAgentNotReadyReasons = (agent: CustomAgent, isAgentMode: boolean): string[] => { const reasons: string[] = [] - const config = settingsStore.agentConfig || { allowedTools: [] } - const models = settingsStore.conversationModels || { summaryModelId: '', rerankModelId: '' } + const config = agent.config || {} - if (!config.allowedTools || config.allowedTools.length === 0) { - reasons.push(t('input.agentMissingAllowedTools')) + // 检查对话模型(Summary Model) + if (!config.model_id || config.model_id.trim() === '') { + reasons.push(t('input.customAgentMissingSummaryModel')) } - if (!models.summaryModelId || models.summaryModelId.trim() === '') { - reasons.push(t('input.agentMissingSummaryModel')) + + // 检查重排模型(Rerank Model)- 如果使用知识库则需要 + if (config.kb_selection_mode !== 'none') { + if (!config.rerank_model_id || config.rerank_model_id.trim() === '') { + reasons.push(t('input.customAgentMissingRerankModel')) + } } - if (!models.rerankModelId || models.rerankModelId.trim() === '') { - reasons.push(t('input.agentMissingRerankModel')) + + // Agent 模式还需要检查允许的工具 + if (isAgentMode) { + if (!config.allowed_tools || config.allowed_tools.length === 0) { + reasons.push(t('input.agentMissingAllowedTools')) + } } return reasons } -const toggleAgentMode = () => { - // 如果要启用 Agent,先检查是否就绪 - // 注意:isAgentReady 是从 store 中计算的,需要确保 store 中的配置是最新的 - if (!isAgentEnabled.value) { - // 尝试启用 Agent,先检查是否就绪 - const agentReady = settingsStore.isAgentReady - if (!agentReady) { - const reasons = getAgentNotReadyReasons() - const reasonsText = reasons.join('、') - - // 创建带跳转链接的自定义消息 - const messageContent = h('div', { style: 'display: flex; flex-direction: column; gap: 8px; max-width: 320px;' }, [ - h('span', { style: 'color: #333; line-height: 1.5;' }, t('input.messages.agentNotReadyDetail', { reasons: reasonsText })), - h('a', { - href: '#', - onClick: (e: Event) => { - e.preventDefault(); - handleGoToAgentSettings(); - }, - style: 'color: #07C05F; text-decoration: none; font-weight: 500; cursor: pointer; align-self: flex-start;', - onMouseenter: (e: Event) => { - (e.target as HTMLElement).style.textDecoration = 'underline'; - }, - onMouseleave: (e: Event) => { - (e.target as HTMLElement).style.textDecoration = 'none'; - } - }, t('input.goToSettings')) - ]); - - MessagePlugin.warning({ - content: () => messageContent, - duration: 5000 - }); - return +// 获取自定义智能体不就绪的原因(非 Agent 模式,快速回答) +const getCustomAgentNotReadyReasons = (agent: CustomAgent): string[] => { + const reasons: string[] = [] + const config = agent.config || {} + + // 检查对话模型(Summary Model) + if (!config.model_id || config.model_id.trim() === '') { + reasons.push(t('input.customAgentMissingSummaryModel')) + } + // 检查重排模型(Rerank Model)- 如果使用知识库则需要 + if (config.kb_selection_mode !== 'none') { + if (!config.rerank_model_id || config.rerank_model_id.trim() === '') { + reasons.push(t('input.customAgentMissingRerankModel')) } } - // 正常切换 Agent 状态 - settingsStore.toggleAgent(!isAgentEnabled.value); - const message = isAgentEnabled.value ? t('input.messages.agentEnabled') : t('input.messages.agentDisabled'); - MessagePlugin.success(message); + return reasons +} + +// 显示自定义智能体未就绪的消息 +const showCustomAgentNotReadyMessage = (agent: CustomAgent, reasons: string[]) => { + const reasonsText = reasons.join('、') + + const messageContent = h('div', { style: 'display: flex; flex-direction: column; gap: 8px; max-width: 320px;' }, [ + h('span', { style: 'color: #333; line-height: 1.5;' }, t('input.customAgentNotReadyDetail', { reasons: reasonsText })), + h('a', { + href: '#', + onClick: (e: Event) => { + e.preventDefault(); + // 跳转到智能体编辑页面 + router.push(`/platform/agents?edit=${agent.id}`); + }, + style: 'color: #07C05F; text-decoration: none; font-weight: 500; cursor: pointer; align-self: flex-start;', + onMouseenter: (e: Event) => { + (e.target as HTMLElement).style.textDecoration = 'underline'; + }, + onMouseleave: (e: Event) => { + (e.target as HTMLElement).style.textDecoration = 'none'; + } + }, t('input.goToAgentEditor')) + ]); + + MessagePlugin.warning({ + content: () => messageContent, + duration: 5000 + }); +} + +// 显示内置智能体未就绪的消息 +const showBuiltinAgentNotReadyMessage = (mode: 'smart-reasoning' | 'quick-answer', reasons: string[]) => { + const agentName = mode === 'smart-reasoning' + ? t('input.builtinAgentSettingName') + : t('input.builtinNormalSettingName'); + const builtinAgentId = mode === 'smart-reasoning' ? BUILTIN_SMART_REASONING_ID : BUILTIN_QUICK_ANSWER_ID; + const reasonsText = reasons.join('、') + + const messageContent = h('div', { style: 'display: flex; flex-direction: column; gap: 8px; max-width: 320px;' }, [ + h('span', { style: 'color: #333; line-height: 1.5;' }, t('input.builtinAgentNotReadyDetail', { agentName, reasons: reasonsText })), + h('a', { + href: '#', + onClick: (e: Event) => { + e.preventDefault(); + // 跳转到内置智能体编辑页面 + router.push(`/platform/agents?edit=${builtinAgentId}`); + }, + style: 'color: #07C05F; text-decoration: none; font-weight: 500; cursor: pointer; align-self: flex-start;', + onMouseenter: (e: Event) => { + (e.target as HTMLElement).style.textDecoration = 'underline'; + }, + onMouseleave: (e: Event) => { + (e.target as HTMLElement).style.textDecoration = 'none'; + } + }, t('input.goToAgentEditor')) + ]); + + MessagePlugin.warning({ + content: () => messageContent, + duration: 5000 + }); } const toggleWebSearch = () => { @@ -1332,12 +1415,6 @@ const toggleWebSearch = () => { MessagePlugin.warning(t('input.webSearchDisabledByAgent')); return; } - - // 如果智能体强制启用了网络搜索,不允许关闭 - if (isWebSearchForcedByAgent.value) { - MessagePlugin.warning(t('input.webSearchForcedByAgent')); - return; - } if (!isWebSearchConfigured.value) { const messageContent = h('div', { style: 'display: flex; flex-direction: column; gap: 6px; max-width: 280px;' }, [ @@ -1472,8 +1549,9 @@ onBeforeRouteUpdate((to, from, next) => { ref="agentModeButtonRef" class="control-btn agent-mode-btn" :class="{ - 'active': isAgentEnabled, - 'agent-active': isAgentEnabled + 'is-normal': !isCustomAgent && !isAgentEnabled, + 'is-agent': !isCustomAgent && isAgentEnabled, + 'is-custom': isCustomAgent }" @click.stop="toggleAgentModeSelector" > @@ -1502,12 +1580,14 @@ onBeforeRouteUpdate((to, from, next) => { /> - + {{ $t('input.webSearchDisabledByAgent') }} - {{ $t('input.webSearchForcedByAgent') }} + {{ isWebSearchEnabled ? $t('input.webSearch.toggleOff') : $t('input.webSearch.toggleOn') }} -
+ @@ -1515,9 +1595,8 @@ onBeforeRouteUpdate((to, from, next) => {
@@ -1528,7 +1607,7 @@ onBeforeRouteUpdate((to, from, next) => { fill="none" xmlns="http://www.w3.org/2000/svg" class="control-icon websearch-icon" - :class="{ 'active': (isWebSearchEnabled && isWebSearchConfigured) || isWebSearchForcedByAgent }" + :class="{ 'active': isWebSearchEnabled && isWebSearchConfigured }" > @@ -1540,13 +1619,20 @@ onBeforeRouteUpdate((to, from, next) => { - + +
{ transition: background 0.12s, border-color 0.12s; position: relative; - &.active, - &.agent-active { - background: linear-gradient(135deg, rgba(16, 185, 129, 0.15) 0%, rgba(16, 185, 129, 0.1) 100%); - border-color: rgba(16, 185, 129, 0.4); - box-shadow: 0 2px 6px rgba(16, 185, 129, 0.12); + // 内置普通模式 - 绿色 + &.is-normal { + background: linear-gradient(135deg, rgba(16, 185, 129, 0.12) 0%, rgba(16, 185, 129, 0.08) 100%); + border-color: rgba(16, 185, 129, 0.35); .agent-mode-text { - color: #07C05F; + color: #059669; font-weight: 600; } - .agent-icon { - filter: brightness(0) saturate(100%) invert(58%) sepia(87%) saturate(1234%) hue-rotate(95deg) brightness(98%) contrast(89%); - } - .dropdown-arrow { - color: #07C05F; + color: #059669; } &:hover { - background: linear-gradient(135deg, rgba(16, 185, 129, 0.2) 0%, rgba(16, 185, 129, 0.15) 100%); - border-color: rgba(16, 185, 129, 0.6); + background: linear-gradient(135deg, rgba(16, 185, 129, 0.18) 0%, rgba(16, 185, 129, 0.12) 100%); + border-color: rgba(16, 185, 129, 0.5); } } - &:not(.agent-active) { - background: var(--td-bg-color-container, #fff); - border-color: var(--td-component-border, #e0e0e0); + // 内置 Agent 模式 - 紫色 + &.is-agent { + background: linear-gradient(135deg, rgba(124, 77, 255, 0.12) 0%, rgba(124, 77, 255, 0.08) 100%); + border-color: rgba(124, 77, 255, 0.35); .agent-mode-text { - color: var(--td-text-color-secondary, #666); + color: #7c4dff; + font-weight: 600; } - .normal-mode-icon { - color: var(--td-text-color-secondary, #666); + .dropdown-arrow { + color: #7c4dff; } &:hover { - background: var(--td-bg-color-container-hover, #fff); - border-color: var(--td-component-stroke, #b0b0b0); + background: linear-gradient(135deg, rgba(124, 77, 255, 0.18) 0%, rgba(124, 77, 255, 0.12) 100%); + border-color: rgba(124, 77, 255, 0.5); + } + } + + // 自定义智能体 - 蓝色 + &.is-custom { + background: linear-gradient(135deg, rgba(59, 130, 246, 0.12) 0%, rgba(59, 130, 246, 0.08) 100%); + border-color: rgba(59, 130, 246, 0.35); + + .agent-mode-text { + color: #3b82f6; + font-weight: 600; + } + + .dropdown-arrow { + color: #3b82f6; + } + + &:hover { + background: linear-gradient(135deg, rgba(59, 130, 246, 0.18) 0%, rgba(59, 130, 246, 0.12) 100%); + border-color: rgba(59, 130, 246, 0.5); } } } @@ -1932,6 +2035,26 @@ const getImgSrc = (url: string) => { flex-shrink: 0; } +.agent-btn-icon { + display: flex; + align-items: center; + justify-content: center; + width: 20px; + height: 20px; + border-radius: 5px; + flex-shrink: 0; + + &.normal { + background: rgba(7, 192, 95, 0.12); + color: #059669; + } + + &.agent { + background: rgba(124, 77, 255, 0.12); + color: #7c4dff; + } +} + .agent-mode-text { font-size: 13px; color: var(--td-text-color-secondary, #666); @@ -2052,22 +2175,29 @@ const getImgSrc = (url: string) => { } } -:global(.websearch-tooltip-disabled) { - display: flex; - flex-direction: column; - gap: 4px; - max-width: 220px; - font-size: 12px; - color: var(--td-text-color-secondary, #666); +:global(.input-field-tooltip) { + .t-popup__content { + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); + border: 1px solid var(--td-component-border, #e7e7e7); + } } -:global(.websearch-tooltip-disabled a) { +:global(.tooltip-with-link) { + display: flex; + flex-direction: column; + gap: 6px; + max-width: 220px; + font-size: 12px; + color: var(--td-text-color-primary, #333); +} + +:global(.tooltip-with-link a) { color: #07C05F; font-weight: 500; text-decoration: none; } -:global(.websearch-tooltip-disabled a:hover) { +:global(.tooltip-with-link a:hover) { text-decoration: underline; } diff --git a/frontend/src/components/UserMenu.vue b/frontend/src/components/UserMenu.vue index 969b6fe6..a835c0d8 100644 --- a/frontend/src/components/UserMenu.vue +++ b/frontend/src/components/UserMenu.vue @@ -24,10 +24,6 @@ Ollama
- @@ -695,13 +820,31 @@

当无法从知识库找到答案时,引导模型生成回复的提示词

+
+ 可用变量: + + + + +
-
+
+ +
+
+
+
+ +
+
{{ placeholder.description }}
+
+
+
+
@@ -732,12 +898,17 @@ import { ref, computed, watch, nextTick } from 'vue'; import { useI18n } from 'vue-i18n'; import { MessagePlugin } from 'tdesign-vue-next'; -import { createAgent, updateAgent, type CustomAgent } from '@/api/agent'; -import { listModels } from '@/api/model'; +import { createAgent, updateAgent, getPlaceholders, type CustomAgent, type PlaceholderDefinition } from '@/api/agent'; +import { listModels, type ModelConfig } from '@/api/model'; import { listKnowledgeBases } from '@/api/knowledge-base'; -import { getAgentConfig, getConversationConfig, type PlaceholderDefinition } from '@/api/system'; +import { listMCPServices, type MCPService } from '@/api/mcp-service'; +import { getAgentConfig, getConversationConfig } from '@/api/system'; +import { useUIStore } from '@/stores/ui'; import AgentAvatar from '@/components/AgentAvatar.vue'; import PromptTemplateSelector from '@/components/PromptTemplateSelector.vue'; +import ModelSelector from '@/components/ModelSelector.vue'; + +const uiStore = useUIStore(); const { t } = useI18n(); @@ -745,6 +916,7 @@ const props = defineProps<{ visible: boolean; mode: 'create' | 'edit'; agent?: CustomAgent | null; + initialSection?: string; }>(); const emit = defineEmits<{ @@ -752,14 +924,16 @@ const emit = defineEmits<{ (e: 'success'): void; }>(); -const currentSection = ref('basic'); +const currentSection = ref(props.initialSection || 'basic'); const saving = ref(false); -const modelOptions = ref<{ label: string; value: string }[]>([]); -const rerankModelOptions = ref<{ label: string; value: string }[]>([]); +const allModels = ref([]); const kbOptions = ref<{ label: string; value: string }[]>([]); +const mcpOptions = ref<{ label: string; value: string }[]>([]); // 系统默认配置(用于内置智能体显示默认提示词) -const defaultSystemPrompt = ref(''); +const defaultSystemPrompt = ref(''); // 普通模式默认提示词 +const defaultSystemPromptWebEnabled = ref(''); // Agent模式 Web开启时默认提示词 +const defaultSystemPromptWebDisabled = ref(''); // Agent模式 Web关闭时默认提示词 const defaultContextTemplate = ref(''); const defaultRewritePromptSystem = ref(''); const defaultRewritePromptUser = ref(''); @@ -780,6 +954,9 @@ const knowledgeBaseTools = ['grep_chunks', 'knowledge_search', 'list_knowledge_c // 知识库选择模式:all=全部, selected=指定, none=不使用 const kbSelectionMode = ref<'all' | 'selected' | 'none'>('none'); +// MCP 服务选择模式:all=全部, selected=指定, none=不使用 +const mcpSelectionMode = ref<'all' | 'selected' | 'none'>('none'); + // 可用工具列表 (与后台 definitions.go 保持一致) const allTools = [ { value: 'thinking', label: '思考', description: '动态和反思性的问题解决思考工具', requiresKB: false }, @@ -797,14 +974,6 @@ const hasKnowledgeBase = computed(() => { return kbSelectionMode.value !== 'none'; }); -// 允许用户选择知识库的描述 -const allowUserKBSelectionDesc = computed(() => { - if (kbSelectionMode.value === 'all') { - return t('agent.editor.allowUserKBSelectionDescAll'); - } - return t('agent.editor.allowUserKBSelectionDescSelected'); -}); - const availableTools = computed(() => { return allTools.map(tool => ({ ...tool, @@ -812,8 +981,40 @@ const availableTools = computed(() => { })); }); -// 占位符相关 -const availablePlaceholders = ref([]); +// 占位符相关 - 从 API 获取 +const placeholderData = ref<{ + system_prompt: PlaceholderDefinition[]; + agent_system_prompt: PlaceholderDefinition[]; + context_template: PlaceholderDefinition[]; + rewrite_system_prompt: PlaceholderDefinition[]; + rewrite_prompt: PlaceholderDefinition[]; + fallback_prompt: PlaceholderDefinition[]; +}>({ + system_prompt: [], + agent_system_prompt: [], + context_template: [], + rewrite_system_prompt: [], + rewrite_prompt: [], + fallback_prompt: [], +}); + +// 系统提示词占位符(根据模式动态选择) +const availablePlaceholders = computed(() => { + return isAgentMode.value ? placeholderData.value.agent_system_prompt : placeholderData.value.system_prompt; +}); + +// 上下文模板占位符 +const contextTemplatePlaceholders = computed(() => placeholderData.value.context_template); + +// 改写系统提示词占位符 +const rewriteSystemPlaceholders = computed(() => placeholderData.value.rewrite_system_prompt); + +// 改写用户提示词占位符 +const rewritePlaceholders = computed(() => placeholderData.value.rewrite_prompt); + +// 兜底提示词占位符 +const fallbackPlaceholders = computed(() => placeholderData.value.fallback_prompt); + const promptTextareaRef = ref(null); const showPlaceholderPopup = ref(false); const selectedPlaceholderIndex = ref(0); @@ -829,13 +1030,30 @@ const contextPlaceholderPrefix = ref(''); const contextPopupStyle = ref({ top: '0px', left: '0px' }); let contextPlaceholderPopupTimer: any = null; -// 上下文模板可用的占位符 -const contextTemplatePlaceholders = computed(() => [ - { name: 'query', description: t('agent.editor.placeholderQuery') || '用户的问题' }, - { name: 'contexts', description: t('agent.editor.placeholderContexts') || '检索到的内容列表' }, - { name: 'current_time', description: t('agent.editor.placeholderCurrentTime') || '当前时间(格式:2006-01-02 15:04:05)' }, - { name: 'current_week', description: t('agent.editor.placeholderCurrentWeek') || '当前星期(如:星期一)' }, -]); +// 通用占位符弹出相关(用于改写提示词和兜底提示词) +interface PlaceholderPopupState { + show: boolean; + selectedIndex: number; + prefix: string; + style: { top: string; left: string }; + timer: any; + fieldKey: string; + placeholders: PlaceholderDefinition[]; +} + +const rewriteSystemPopup = ref({ + show: false, selectedIndex: 0, prefix: '', style: { top: '0px', left: '0px' }, timer: null, fieldKey: 'rewrite_prompt_system', placeholders: [] +}); +const rewriteUserPopup = ref({ + show: false, selectedIndex: 0, prefix: '', style: { top: '0px', left: '0px' }, timer: null, fieldKey: 'rewrite_prompt_user', placeholders: [] +}); +const fallbackPromptPopup = ref({ + show: false, selectedIndex: 0, prefix: '', style: { top: '0px', left: '0px' }, timer: null, fieldKey: 'fallback_prompt', placeholders: [] +}); + +const rewriteSystemTextareaRef = ref(null); +const rewriteUserTextareaRef = ref(null); +const fallbackPromptTextareaRef = ref(null); const navItems = computed(() => { const items: { key: string; icon: string; label: string }[] = [ @@ -869,11 +1087,10 @@ const navItems = computed(() => { const defaultFormData = { name: '', description: '', - type: 'custom' as const, is_builtin: false, config: { // 基础设置 - agent_mode: 'normal' as 'normal' | 'agent', + agent_mode: 'quick-answer' as 'quick-answer' | 'smart-reasoning', system_prompt: '', system_prompt_web_enabled: '', context_template: '{{query}}', @@ -886,10 +1103,12 @@ const defaultFormData = { max_iterations: 10, allowed_tools: [] as string[], reflection_enabled: false, + // MCP 服务设置 + mcp_selection_mode: 'none' as 'all' | 'selected' | 'none', + mcp_services: [] as string[], // 知识库设置 kb_selection_mode: 'none' as 'all' | 'selected' | 'none', knowledge_bases: [] as string[], - allow_user_kb_selection: false, // 网络搜索设置 web_search_enabled: false, web_search_max_results: 5, @@ -919,29 +1138,33 @@ const defaultFormData = { const formData = ref(JSON.parse(JSON.stringify(defaultFormData))); const agentMode = computed({ get: () => formData.value.config.agent_mode, - set: (val: 'normal' | 'agent') => { formData.value.config.agent_mode = val; } + set: (val: 'quick-answer' | 'smart-reasoning') => { formData.value.config.agent_mode = val; } }); -const isAgentMode = computed(() => agentMode.value === 'agent'); +const isAgentMode = computed(() => agentMode.value === 'smart-reasoning'); // 是否为内置智能体 const isBuiltinAgent = computed(() => { return formData.value.is_builtin === true; }); -// 系统提示词的 placeholder(内置智能体显示默认提示词,自定义智能体显示普通提示) +// 系统提示词的 placeholder const systemPromptPlaceholder = computed(() => { - if (isBuiltinAgent.value && defaultSystemPrompt.value) { - return t('agent.editor.defaultPromptHint') + '\n\n' + defaultSystemPrompt.value; - } return t('agent.editor.systemPromptPlaceholder'); }); -// 上下文模板的 placeholder(内置智能体显示默认模板,自定义智能体显示普通提示) +// Agent模式 Web关闭时的 placeholder +const systemPromptWebDisabledPlaceholder = computed(() => { + return t('agent.editor.systemPromptPlaceholder'); +}); + +// Agent模式 Web开启时的 placeholder +const systemPromptWebEnabledPlaceholder = computed(() => { + return t('agent.editor.systemPromptWebEnabledPlaceholder') || '网络搜索开启时使用的系统提示词'; +}); + +// 上下文模板的 placeholder const contextTemplatePlaceholder = computed(() => { - if (isBuiltinAgent.value && defaultContextTemplate.value) { - return t('agent.editor.defaultContextTemplateHint') + '\n\n' + defaultContextTemplate.value; - } return t('agent.editor.contextTemplatePlaceholder'); }); @@ -956,7 +1179,7 @@ const needsRerankModel = computed(() => { // 监听可见性变化,重置表单 watch(() => props.visible, async (val) => { if (val) { - currentSection.value = 'basic'; + currentSection.value = props.initialSection || 'basic'; // 先加载依赖数据(包括默认配置) await loadDependencies(); @@ -976,16 +1199,22 @@ watch(() => props.visible, async (val) => { if (!agentData.config.suggested_prompts) agentData.config.suggested_prompts = []; 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 = []; // 兼容旧数据:如果没有 agent_mode 字段,根据 allowed_tools 推断 if (!agentData.config.agent_mode) { const isAgent = agentData.config.max_iterations > 1 || (agentData.config.allowed_tools && agentData.config.allowed_tools.length > 0); - agentData.config.agent_mode = isAgent ? 'agent' : 'normal'; + agentData.config.agent_mode = isAgent ? 'smart-reasoning' : 'quick-answer'; } formData.value = agentData; // 初始化知识库选择模式 initKbSelectionMode(); + initMcpSelectionMode(); + // 内置智能体:如果提示词为空,填入系统默认值 + if (agentData.is_builtin) { + fillBuiltinAgentDefaults(); + } } else { // 创建新智能体,使用系统默认值 const newFormData = JSON.parse(JSON.stringify(defaultFormData)); @@ -1003,6 +1232,7 @@ watch(() => props.visible, async (val) => { } formData.value = newFormData; kbSelectionMode.value = 'none'; + mcpSelectionMode.value = 'none'; } } }); @@ -1015,21 +1245,68 @@ const initKbSelectionMode = () => { } else if (formData.value.config.knowledge_bases?.length > 0) { // 有指定知识库 kbSelectionMode.value = 'selected'; - } else if (formData.value.config.allow_user_kb_selection) { - // 允许用户选择(旧数据兼容:没有指定知识库但允许选择 = 全部) - kbSelectionMode.value = 'all'; } else { kbSelectionMode.value = 'none'; } }; +// 初始化 MCP 选择模式 +const initMcpSelectionMode = () => { + if (formData.value.config.mcp_selection_mode) { + // 如果有保存的模式,直接使用 + mcpSelectionMode.value = formData.value.config.mcp_selection_mode; + } else if (formData.value.config.mcp_services?.length > 0) { + // 有指定 MCP 服务 + mcpSelectionMode.value = 'selected'; + } else { + mcpSelectionMode.value = 'none'; + } +}; + +// 内置智能体:填入系统默认值 +const fillBuiltinAgentDefaults = () => { + const config = formData.value.config; + const isAgent = config.agent_mode === 'smart-reasoning'; + + if (isAgent) { + // Agent 模式:填入 Web 开启/关闭的默认提示词 + if (!config.system_prompt && defaultSystemPromptWebDisabled.value) { + config.system_prompt = defaultSystemPromptWebDisabled.value; + } + if (!config.system_prompt_web_enabled && defaultSystemPromptWebEnabled.value) { + config.system_prompt_web_enabled = defaultSystemPromptWebEnabled.value; + } + } else { + // 普通模式:填入默认系统提示词和上下文模板 + if (!config.system_prompt && defaultSystemPrompt.value) { + config.system_prompt = defaultSystemPrompt.value; + } + if (!config.context_template && defaultContextTemplate.value) { + config.context_template = defaultContextTemplate.value; + } + } + + // 通用默认值 + if (!config.rewrite_prompt_system && defaultRewritePromptSystem.value) { + config.rewrite_prompt_system = defaultRewritePromptSystem.value; + } + if (!config.rewrite_prompt_user && defaultRewritePromptUser.value) { + config.rewrite_prompt_user = defaultRewritePromptUser.value; + } + if (!config.fallback_prompt && defaultFallbackPrompt.value) { + config.fallback_prompt = defaultFallbackPrompt.value; + } + if (!config.fallback_response && defaultFallbackResponse.value) { + config.fallback_response = defaultFallbackResponse.value; + } +}; + // 监听知识库选择模式变化 watch(kbSelectionMode, (mode) => { formData.value.config.kb_selection_mode = mode; if (mode === 'none') { // 不使用知识库,清空相关配置 formData.value.config.knowledge_bases = []; - formData.value.config.allow_user_kb_selection = false; } else if (mode === 'all') { // 全部知识库,清空指定列表 formData.value.config.knowledge_bases = []; @@ -1037,9 +1314,22 @@ watch(kbSelectionMode, (mode) => { // selected 模式保持 knowledge_bases 不变 }); +// 监听 MCP 选择模式变化 +watch(mcpSelectionMode, (mode) => { + formData.value.config.mcp_selection_mode = mode; + if (mode === 'none') { + // 不使用 MCP,清空相关配置 + formData.value.config.mcp_services = []; + } else if (mode === 'all') { + // 全部 MCP,清空指定列表 + formData.value.config.mcp_services = []; + } + // selected 模式保持 mcp_services 不变 +}); + // 监听模式变化,自动调整配置 watch(agentMode, (val) => { - if (val === 'agent') { + if (val === 'smart-reasoning') { // 切换到 Agent 模式,根据知识库配置启用工具 if (formData.value.config.allowed_tools.length === 0) { if (hasKnowledgeBase.value) { @@ -1106,16 +1396,10 @@ watch(isAgentMode, (isAgent) => { // 加载依赖数据 const loadDependencies = async () => { try { - // 加载模型列表 (只加载 KnowledgeQA 类型的模型) - const models = await listModels('KnowledgeQA'); + // 加载所有模型列表(ModelSelector 组件会自动按类型过滤) + const models = await listModels(); if (models && models.length > 0) { - modelOptions.value = models.map((m: any) => ({ label: m.name || m.id, value: m.id })); - } - - // 加载 ReRank 模型列表 - const rerankModels = await listModels('Rerank'); - if (rerankModels && rerankModels.length > 0) { - rerankModelOptions.value = rerankModels.map((m: any) => ({ label: m.name || m.id, value: m.id })); + allModels.value = models; } // 加载知识库列表 @@ -1124,10 +1408,35 @@ const loadDependencies = async () => { kbOptions.value = kbRes.data.map((kb: any) => ({ label: kb.name, value: kb.id })); } - // 加载可用占位符 + // 加载 MCP 服务列表(只加载启用的) + try { + const mcpList = await listMCPServices(); + if (mcpList && mcpList.length > 0) { + mcpOptions.value = mcpList + .filter((mcp: MCPService) => mcp.enabled) + .map((mcp: MCPService) => ({ label: mcp.name, value: mcp.id })); + } + } catch (e) { + console.warn('Failed to load MCP services', e); + } + + // 加载占位符定义(从统一 API) + try { + const placeholdersRes = await getPlaceholders(); + if (placeholdersRes.data) { + placeholderData.value = placeholdersRes.data; + } + } catch (e) { + console.warn('Failed to load placeholders', e); + } + + // 加载 Agent 模式默认提示词 const agentConfig = await getAgentConfig(); - if (agentConfig.data?.available_placeholders) { - availablePlaceholders.value = agentConfig.data.available_placeholders; + if (agentConfig.data?.system_prompt_web_enabled) { + defaultSystemPromptWebEnabled.value = agentConfig.data.system_prompt_web_enabled; + } + if (agentConfig.data?.system_prompt_web_disabled) { + defaultSystemPromptWebDisabled.value = agentConfig.data.system_prompt_web_disabled; } // 加载系统默认配置(用于内置智能体显示默认提示词) @@ -1177,9 +1486,17 @@ const loadDependencies = async () => { } }; +// 跳转到模型管理页面添加模型 +const handleAddModel = (subSection: string) => { + uiStore.openSettings('models', subSection); +}; + const handleClose = () => { showPlaceholderPopup.value = false; showContextPlaceholderPopup.value = false; + rewriteSystemPopup.value.show = false; + rewriteUserPopup.value.show = false; + fallbackPromptPopup.value.show = false; emit('update:visible', false); }; @@ -1205,6 +1522,39 @@ const filteredContextPlaceholders = computed(() => { ); }); +// 过滤后的改写系统提示词占位符列表 +const filteredRewriteSystemPlaceholders = computed(() => { + if (!rewriteSystemPopup.value.prefix) { + return rewriteSystemPlaceholders.value; + } + const prefix = rewriteSystemPopup.value.prefix.toLowerCase(); + return rewriteSystemPlaceholders.value.filter(p => + p.name.toLowerCase().startsWith(prefix) + ); +}); + +// 过滤后的改写用户提示词占位符列表 +const filteredRewriteUserPlaceholders = computed(() => { + if (!rewriteUserPopup.value.prefix) { + return rewritePlaceholders.value; + } + const prefix = rewriteUserPopup.value.prefix.toLowerCase(); + return rewritePlaceholders.value.filter(p => + p.name.toLowerCase().startsWith(prefix) + ); +}); + +// 过滤后的兜底提示词占位符列表 +const filteredFallbackPlaceholders = computed(() => { + if (!fallbackPromptPopup.value.prefix) { + return fallbackPlaceholders.value; + } + const prefix = fallbackPromptPopup.value.prefix.toLowerCase(); + return fallbackPlaceholders.value.filter(p => + p.name.toLowerCase().startsWith(prefix) + ); +}); + // 获取 textarea 元素 const getTextareaElement = (): HTMLTextAreaElement | null => { if (promptTextareaRef.value) { @@ -1310,7 +1660,7 @@ const handlePromptInput = () => { }; // 插入占位符 -const insertPlaceholder = (placeholderName: string) => { +const insertPlaceholder = (placeholderName: string, fromPopup: boolean = false) => { const textarea = getTextareaElement(); if (!textarea) return; @@ -1320,30 +1670,43 @@ const insertPlaceholder = (placeholderName: string) => { nextTick(() => { const cursorPos = textarea.selectionStart; - const currentValue = formData.value.config.system_prompt; + const currentValue = formData.value.config.system_prompt || ''; const textBeforeCursor = currentValue.substring(0, cursorPos); const textAfterCursor = currentValue.substring(cursorPos); - // 找到 {{ 的位置 - let lastOpenPos = -1; - for (let i = textBeforeCursor.length - 1; i >= 1; i--) { - if (textBeforeCursor[i] === '{' && textBeforeCursor[i - 1] === '{') { - lastOpenPos = i - 1; - break; + // 只有从下拉列表选择时才查找 {{ 并替换 + if (fromPopup) { + let lastOpenPos = -1; + for (let i = textBeforeCursor.length - 1; i >= 1; i--) { + if (textBeforeCursor[i] === '{' && textBeforeCursor[i - 1] === '{') { + lastOpenPos = i - 1; + break; + } + } + + if (lastOpenPos !== -1) { + const textBeforeOpen = currentValue.substring(0, lastOpenPos); + const newValue = textBeforeOpen + `{{${placeholderName}}}` + textAfterCursor; + formData.value.config.system_prompt = newValue; + + nextTick(() => { + const newCursorPos = textBeforeOpen.length + placeholderName.length + 4; + textarea.setSelectionRange(newCursorPos, newCursorPos); + textarea.focus(); + }); + return; } } - if (lastOpenPos !== -1) { - const textBeforeOpen = currentValue.substring(0, lastOpenPos); - const newValue = textBeforeOpen + `{{${placeholderName}}}` + textAfterCursor; - formData.value.config.system_prompt = newValue; - - nextTick(() => { - const newCursorPos = textBeforeOpen.length + placeholderName.length + 4; - textarea.setSelectionRange(newCursorPos, newCursorPos); - textarea.focus(); - }); - } + // 直接在光标位置插入完整占位符 + const newValue = textBeforeCursor + `{{${placeholderName}}}` + textAfterCursor; + formData.value.config.system_prompt = newValue; + + nextTick(() => { + const newCursorPos = cursorPos + placeholderName.length + 4; + textarea.setSelectionRange(newCursorPos, newCursorPos); + textarea.focus(); + }); }); }; @@ -1449,7 +1812,7 @@ const handleContextTemplateInput = () => { }; // 插入上下文模板占位符 -const insertContextPlaceholder = (placeholderName: string) => { +const insertContextPlaceholder = (placeholderName: string, fromPopup: boolean = false) => { const textarea = getContextTemplateTextareaElement(); if (!textarea) return; @@ -1459,29 +1822,238 @@ const insertContextPlaceholder = (placeholderName: string) => { nextTick(() => { const cursorPos = textarea.selectionStart; - const currentValue = formData.value.config.context_template; + const currentValue = formData.value.config.context_template || ''; const textBeforeCursor = currentValue.substring(0, cursorPos); const textAfterCursor = currentValue.substring(cursorPos); - let lastOpenPos = -1; - for (let i = textBeforeCursor.length - 1; i >= 1; i--) { - if (textBeforeCursor[i] === '{' && textBeforeCursor[i - 1] === '{') { + // 只有从下拉列表选择时才查找 {{ 并替换 + if (fromPopup) { + let lastOpenPos = -1; + for (let i = textBeforeCursor.length - 1; i >= 1; i--) { + if (textBeforeCursor[i] === '{' && textBeforeCursor[i - 1] === '{') { + lastOpenPos = i - 1; + break; + } + } + + if (lastOpenPos !== -1) { + const textBeforeOpen = currentValue.substring(0, lastOpenPos); + const newValue = textBeforeOpen + `{{${placeholderName}}}` + textAfterCursor; + formData.value.config.context_template = newValue; + + nextTick(() => { + const newCursorPos = textBeforeOpen.length + placeholderName.length + 4; + textarea.setSelectionRange(newCursorPos, newCursorPos); + textarea.focus(); + }); + return; + } + } + + // 直接在光标位置插入完整占位符 + const newValue = textBeforeCursor + `{{${placeholderName}}}` + textAfterCursor; + formData.value.config.context_template = newValue; + + nextTick(() => { + const newCursorPos = cursorPos + placeholderName.length + 4; + textarea.setSelectionRange(newCursorPos, newCursorPos); + textarea.focus(); + }); + }); +}; + +// 通用获取 textarea 元素 +const getGenericTextareaElement = (type: 'rewriteSystem' | 'rewriteUser' | 'fallback'): HTMLTextAreaElement | null => { + const refMap = { + rewriteSystem: rewriteSystemTextareaRef, + rewriteUser: rewriteUserTextareaRef, + fallback: fallbackPromptTextareaRef, + }; + const ref = refMap[type]; + if (ref.value) { + if (ref.value.$el) { + return ref.value.$el.querySelector('textarea'); + } + if (ref.value instanceof HTMLTextAreaElement) { + return ref.value; + } + } + return null; +}; + +// 通用计算光标位置 +const calculateGenericCursorPosition = (textarea: HTMLTextAreaElement, fieldValue: string) => { + const cursorPos = textarea.selectionStart; + const textBeforeCursor = fieldValue.substring(0, cursorPos); + const lines = textBeforeCursor.split('\n'); + const currentLine = lines.length - 1; + const currentLineText = lines[currentLine]; + + const textareaRect = textarea.getBoundingClientRect(); + const style = window.getComputedStyle(textarea); + const lineHeight = parseFloat(style.lineHeight) || 20; + const paddingTop = parseFloat(style.paddingTop) || 0; + const paddingLeft = parseFloat(style.paddingLeft) || 0; + + const span = document.createElement('span'); + span.style.font = style.font; + span.style.visibility = 'hidden'; + span.style.position = 'absolute'; + span.style.whiteSpace = 'pre'; + span.textContent = currentLineText; + document.body.appendChild(span); + const textWidth = span.offsetWidth; + document.body.removeChild(span); + + const scrollTop = textarea.scrollTop; + const top = textareaRect.top + paddingTop + (currentLine * lineHeight) - scrollTop + lineHeight + 4; + const scrollLeft = textarea.scrollLeft; + const left = textareaRect.left + paddingLeft + textWidth - scrollLeft; + + return { top, left }; +}; + +// 通用检查并显示占位符弹出 +const checkAndShowGenericPlaceholderPopup = ( + type: 'rewriteSystem' | 'rewriteUser' | 'fallback', + popup: typeof rewriteSystemPopup, + fieldKey: keyof typeof formData.value.config, + filteredPlaceholders: PlaceholderDefinition[] +) => { + const textarea = getGenericTextareaElement(type); + if (!textarea) return; + + const cursorPos = textarea.selectionStart; + const fieldValue = String(formData.value.config[fieldKey] || ''); + const textBeforeCursor = fieldValue.substring(0, cursorPos); + + let lastOpenPos = -1; + for (let i = textBeforeCursor.length - 1; i >= 1; i--) { + if (textBeforeCursor[i] === '{' && textBeforeCursor[i - 1] === '{') { + const textAfterOpen = textBeforeCursor.substring(i + 1); + if (!textAfterOpen.includes('}}')) { lastOpenPos = i - 1; break; } } + } + + if (lastOpenPos === -1) { + popup.value.show = false; + popup.value.prefix = ''; + return; + } + + const textAfterOpen = textBeforeCursor.substring(lastOpenPos + 2); + popup.value.prefix = textAfterOpen; + + if (filteredPlaceholders.length > 0) { + nextTick(() => { + const position = calculateGenericCursorPosition(textarea, fieldValue); + popup.value.style = { + top: `${position.top}px`, + left: `${position.left}px` + }; + popup.value.show = true; + popup.value.selectedIndex = 0; + }); + } else { + popup.value.show = false; + } +}; + +// 处理改写系统提示词输入 +const handleRewriteSystemInput = () => { + if (rewriteSystemPopup.value.timer) { + clearTimeout(rewriteSystemPopup.value.timer); + } + rewriteSystemPopup.value.timer = setTimeout(() => { + checkAndShowGenericPlaceholderPopup('rewriteSystem', rewriteSystemPopup, 'rewrite_prompt_system', filteredRewriteSystemPlaceholders.value); + }, 50); +}; + +// 处理改写用户提示词输入 +const handleRewriteUserInput = () => { + if (rewriteUserPopup.value.timer) { + clearTimeout(rewriteUserPopup.value.timer); + } + rewriteUserPopup.value.timer = setTimeout(() => { + checkAndShowGenericPlaceholderPopup('rewriteUser', rewriteUserPopup, 'rewrite_prompt_user', filteredRewriteUserPlaceholders.value); + }, 50); +}; + +// 处理兜底提示词输入 +const handleFallbackPromptInput = () => { + if (fallbackPromptPopup.value.timer) { + clearTimeout(fallbackPromptPopup.value.timer); + } + fallbackPromptPopup.value.timer = setTimeout(() => { + checkAndShowGenericPlaceholderPopup('fallback', fallbackPromptPopup, 'fallback_prompt', filteredFallbackPlaceholders.value); + }, 50); +}; + +// 通用插入占位符 +const insertGenericPlaceholder = (type: 'rewriteSystem' | 'rewriteUser' | 'fallback', placeholderName: string, fromPopup: boolean = false) => { + const textarea = getGenericTextareaElement(type); + if (!textarea) return; + + const popupMap = { + rewriteSystem: rewriteSystemPopup, + rewriteUser: rewriteUserPopup, + fallback: fallbackPromptPopup, + }; + const fieldKeyMap: Record = { + rewriteSystem: 'rewrite_prompt_system', + rewriteUser: 'rewrite_prompt_user', + fallback: 'fallback_prompt', + }; + + const popup = popupMap[type]; + const fieldKey = fieldKeyMap[type]; + + popup.value.show = false; + popup.value.prefix = ''; + popup.value.selectedIndex = 0; + + nextTick(() => { + const cursorPos = textarea.selectionStart; + const currentValue = String(formData.value.config[fieldKey] || ''); + const textBeforeCursor = currentValue.substring(0, cursorPos); + const textAfterCursor = currentValue.substring(cursorPos); - if (lastOpenPos !== -1) { - const textBeforeOpen = currentValue.substring(0, lastOpenPos); - const newValue = textBeforeOpen + `{{${placeholderName}}}` + textAfterCursor; - formData.value.config.context_template = newValue; + // 只有从下拉列表选择时才查找 {{ 并替换 + if (fromPopup) { + let lastOpenPos = -1; + for (let i = textBeforeCursor.length - 1; i >= 1; i--) { + if (textBeforeCursor[i] === '{' && textBeforeCursor[i - 1] === '{') { + lastOpenPos = i - 1; + break; + } + } - nextTick(() => { - const newCursorPos = textBeforeOpen.length + placeholderName.length + 4; - textarea.setSelectionRange(newCursorPos, newCursorPos); - textarea.focus(); - }); + if (lastOpenPos !== -1) { + const textBeforeOpen = currentValue.substring(0, lastOpenPos); + const newValue = textBeforeOpen + `{{${placeholderName}}}` + textAfterCursor; + (formData.value.config as any)[fieldKey] = newValue; + + nextTick(() => { + const newCursorPos = textBeforeOpen.length + placeholderName.length + 4; + textarea.setSelectionRange(newCursorPos, newCursorPos); + textarea.focus(); + }); + return; + } } + + // 直接在光标位置插入完整占位符 + const newValue = textBeforeCursor + `{{${placeholderName}}}` + textAfterCursor; + (formData.value.config as any)[fieldKey] = newValue; + + nextTick(() => { + const newCursorPos = cursorPos + placeholderName.length + 4; + textarea.setSelectionRange(newCursorPos, newCursorPos); + textarea.focus(); + }); }); }; @@ -1513,7 +2085,7 @@ const setupContextTemplateEventListeners = () => { e.stopPropagation(); const selected = filteredContextPlaceholders.value[selectedContextPlaceholderIndex.value]; if (selected) { - insertContextPlaceholder(selected.name); + insertContextPlaceholder(selected.name, true); } } else if (e.key === 'Escape') { e.preventDefault(); @@ -1555,7 +2127,7 @@ const setupTextareaEventListeners = () => { e.stopPropagation(); const selected = filteredPlaceholders.value[selectedPlaceholderIndex.value]; if (selected) { - insertPlaceholder(selected.name); + insertPlaceholder(selected.name, true); } } else if (e.key === 'Escape') { e.preventDefault(); @@ -1569,12 +2141,73 @@ const setupTextareaEventListeners = () => { }); }; +// 通用设置 textarea 事件监听 +const setupGenericTextareaEventListeners = ( + type: 'rewriteSystem' | 'rewriteUser' | 'fallback', + popup: typeof rewriteSystemPopup, + filteredPlaceholders: () => PlaceholderDefinition[] +) => { + nextTick(() => { + const textarea = getGenericTextareaElement(type); + if (textarea) { + textarea.addEventListener('keydown', (e: KeyboardEvent) => { + const filtered = filteredPlaceholders(); + if (popup.value.show && filtered.length > 0) { + if (e.key === 'ArrowDown') { + e.preventDefault(); + e.stopPropagation(); + if (popup.value.selectedIndex < filtered.length - 1) { + popup.value.selectedIndex++; + } else { + popup.value.selectedIndex = 0; + } + } else if (e.key === 'ArrowUp') { + e.preventDefault(); + e.stopPropagation(); + if (popup.value.selectedIndex > 0) { + popup.value.selectedIndex--; + } else { + popup.value.selectedIndex = filtered.length - 1; + } + } else if (e.key === 'Enter' || e.key === 'Tab') { + e.preventDefault(); + e.stopPropagation(); + const selected = filtered[popup.value.selectedIndex]; + if (selected) { + insertGenericPlaceholder(type, selected.name, true); + } + } else if (e.key === 'Escape') { + e.preventDefault(); + e.stopPropagation(); + popup.value.show = false; + popup.value.prefix = ''; + } + } + }, true); + } + }); +}; + +// 处理点击占位符标签 +const handlePlaceholderClick = (type: 'system' | 'context' | 'rewriteSystem' | 'rewriteUser' | 'fallback', placeholderName: string) => { + if (type === 'system') { + insertPlaceholder(placeholderName); + } else if (type === 'context') { + insertContextPlaceholder(placeholderName); + } else { + insertGenericPlaceholder(type, placeholderName); + } +}; + // 监听 visible 变化设置事件监听 watch(() => props.visible, (val) => { if (val) { nextTick(() => { setupTextareaEventListeners(); setupContextTemplateEventListeners(); + setupGenericTextareaEventListeners('rewriteSystem', rewriteSystemPopup, () => filteredRewriteSystemPlaceholders.value); + setupGenericTextareaEventListeners('rewriteUser', rewriteUserPopup, () => filteredRewriteUserPlaceholders.value); + setupGenericTextareaEventListeners('fallback', fallbackPromptPopup, () => filteredFallbackPlaceholders.value); }); } }); @@ -1650,11 +2283,6 @@ const handleSave = async () => { formData.value.config.suggested_prompts = formData.value.config.suggested_prompts.filter((p: string) => p.trim() !== ''); } - // 确保类型设置正确(内置智能体保持原类型) - if (!isBuiltinAgent.value) { - formData.value.type = 'custom'; - } - saving.value = true; try { if (props.mode === 'create') { @@ -1854,6 +2482,11 @@ const handleSave = async () => { &.setting-row-vertical { flex-direction: column; gap: 12px; + + .setting-info { + max-width: 100%; + padding-right: 0; + } } } @@ -2194,46 +2827,64 @@ const handleSave = async () => { } } -// 占位符提示样式 -.placeholder-hint { - margin-top: 12px; - padding: 12px; - background: #f8fafc; - border-radius: 6px; - border: 1px solid #e1e8ed; +// 占位符标签组样式 +.placeholder-tags { + margin-top: 6px; + display: flex; + align-items: center; + gap: 5px; font-size: 12px; - max-width: 480px; - - .hint-title { - font-weight: 500; - color: #333; - margin: 0 0 8px 0; + line-height: 1.4; + overflow-x: auto; + white-space: nowrap; + padding-bottom: 4px; + + // 隐藏滚动条但保持可滚动 + scrollbar-width: thin; + &::-webkit-scrollbar { + height: 4px; + } + &::-webkit-scrollbar-thumb { + background: rgba(0, 0, 0, 0.1); + border-radius: 2px; } - .placeholder-list { - margin: 8px 0; - padding-left: 20px; - color: #666; + .placeholder-label { + color: var(--td-text-color-secondary, #666); + flex-shrink: 0; + } - li { - margin: 4px 0; + .placeholder-hint { + color: var(--td-text-color-placeholder, #999); + font-size: 11px; + user-select: none; + flex-shrink: 0; + } - code { - background: #fff; - padding: 2px 6px; - border-radius: 3px; - font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; - font-size: 11px; - color: #e83e8c; - border: 1px solid #e1e8ed; - } + .placeholder-tag { + display: inline-flex; + align-items: center; + padding: 1px 5px; + border-radius: 3px; + font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; + font-size: 11px; + color: var(--td-text-color-primary, #333); + background-color: var(--td-bg-color-secondarycontainer, #f3f3f3); + cursor: pointer; + transition: all 0.2s; + user-select: none; + border: 1px solid transparent; + flex-shrink: 0; + + &:hover { + color: var(--td-brand-color, #0052d9); + background-color: var(--td-brand-color-light, #ecf2fe); + border-color: var(--td-brand-color-focus, #d0e0fd); } - } - .hint-tip { - margin: 8px 0 0 0; - color: #999; - font-style: italic; + &:active { + background-color: var(--td-brand-color-focus, #d0e0fd); + } } } @@ -2244,43 +2895,43 @@ const handleSave = async () => { } .placeholder-popup { - background: #fff; - border: 1px solid #e5e7eb; - border-radius: 4px; - box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); - max-width: 400px; - max-height: 300px; + background: var(--td-bg-color-container, #fff); + border: 1px solid var(--td-component-stroke, #e5e7eb); + border-radius: 6px; + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12); + max-width: 320px; + max-height: 240px; overflow-y: auto; - padding: 4px 0; + padding: 4px; } .placeholder-item { - padding: 8px 12px; + padding: 6px 10px; cursor: pointer; - transition: background-color 0.2s; + transition: background-color 0.15s; + border-radius: 4px; &:hover, &.active { - background-color: #f5f7fa; + background-color: var(--td-bg-color-container-hover, #f5f7fa); } .placeholder-name { - font-weight: 500; - margin-bottom: 4px; + margin-bottom: 2px; code { - background: #f5f7fa; - padding: 2px 6px; + background: var(--td-bg-color-container-hover, #f5f7fa); + padding: 2px 5px; border-radius: 3px; font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; - font-size: 12px; - color: #e83e8c; + font-size: 11px; + color: var(--td-brand-color, #0052d9); } } .placeholder-desc { - font-size: 12px; - color: #666; + font-size: 11px; + color: var(--td-text-color-secondary, #666); } } @@ -2303,6 +2954,27 @@ const handleSave = async () => { } } +// 内置智能体头像 +.builtin-avatar { + display: flex; + align-items: center; + justify-content: center; + width: 48px; + height: 48px; + border-radius: 12px; + flex-shrink: 0; + + &.normal { + background: linear-gradient(135deg, rgba(7, 192, 95, 0.15) 0%, rgba(7, 192, 95, 0.08) 100%); + color: #059669; + } + + &.agent { + background: linear-gradient(135deg, rgba(124, 77, 255, 0.15) 0%, rgba(124, 77, 255, 0.08) 100%); + color: #7c4dff; + } +} + // 提示词开关 .prompt-toggle { display: flex; diff --git a/frontend/src/views/agent/AgentList.vue b/frontend/src/views/agent/AgentList.vue index f218a83d..f373d49c 100644 --- a/frontend/src/views/agent/AgentList.vue +++ b/frontend/src/views/agent/AgentList.vue @@ -17,8 +17,8 @@ class="agent-card" :class="{ 'is-builtin': agent.is_builtin, - 'agent-mode-normal': agent.config?.agent_mode === 'normal', - 'agent-mode-agent': agent.config?.agent_mode === 'agent' + 'agent-mode-normal': agent.config?.agent_mode === 'quick-answer', + 'agent-mode-agent': agent.config?.agent_mode === 'smart-reasoning' }" @click="handleCardClick(agent)" > @@ -35,15 +35,15 @@
- - {{ agent.name }} -
- - {{ $t('agent.builtin') }} + +
+
+ + + {{ agent.name }}
{{ $t('common.edit') }}
- - -
- -
@@ -87,11 +87,12 @@
-
- - {{ agent.config?.agent_mode === 'agent' ? $t('agent.mode.agent') : $t('agent.mode.normal') }} -
+ +
+ +
+
- {{ formatDate(agent.updated_at) }} +
+ + {{ $t('agent.builtin') }} +
+ {{ formatDate(agent.updated_at) }}
@@ -149,6 +154,7 @@ :visible="editorVisible" :mode="editorMode" :agent="editingAgent" + :initialSection="editorInitialSection" @update:visible="editorVisible = $event" @success="handleEditorSuccess" /> @@ -157,14 +163,17 @@