diff --git a/config/config.yaml b/config/config.yaml index 5f8a19e2..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: @@ -182,7 +177,6 @@ conversation: prompt: | 你是一个专业的智能信息检索助手,名为WeKnora。你犹如专业的高级秘书,依据检索到的信息回答用户问题,不能利用任何先验知识。 当用户提出问题时,助手会基于特定的信息进行解答。助手首先在心中思考推理过程,然后向用户提供答案。 - context_template: | ## 回答问题规则 - 仅根据检索到的信息中的事实进行回复,不得运用任何先验知识,保持回应的客观性和准确性。 - 复杂问题和答案的按Markdown分结构展示,总述部分不需要拆分 @@ -195,18 +189,7 @@ conversation: - 以Markdown图文格式输出你的最终结果 - 输出内容要保证简短且全面,条理清晰,信息明确,不重复。 - ## 当前时间是: - {{.CurrentTime}} {{.CurrentWeek}} - - ## 检索到的信息如下: - ------BEGIN------ - {{range .Contexts}} - {{.}} - {{end}} - ------END------ - - ## 用户当前的问题是: - {{.Query}} + context_template: "{{query}}" extract_entities_prompt: | ## 任务 用户提供的文本中,提取所有符合以下实体类型的实体: @@ -495,11 +478,11 @@ conversation: generate_questions_prompt: | 你是一个专业的问题生成助手。你的任务是根据给定的【主要内容】生成用户可能会问的相关问题。 - {{.Context}} + {{context}} ## 主要内容(请基于此内容生成问题) - 文档名称:{{.DocName}} + 文档名称:{{doc_name}} 文档内容: - {{.Content}} + {{content}} ## 核心要求 - 生成的问题必须与【主要内容】直接相关 @@ -508,7 +491,7 @@ conversation: - 问题应该是用户在实际场景中可能会提出的自然问题 - 问题应该多样化,覆盖内容的不同方面 - 每个问题应该简洁明了,长度控制在30字以内 - - 生成的问题数量为 {{.QuestionCount}} 个 + - 生成的问题数量为 {{question_count}} 个 ## 问题类型建议 - 定义类:什么是...?...是什么? diff --git a/config/prompt_templates/context_template.yaml b/config/prompt_templates/context_template.yaml new file mode 100644 index 00000000..4965fed1 --- /dev/null +++ b/config/prompt_templates/context_template.yaml @@ -0,0 +1,65 @@ +# 上下文模板 +templates: + - id: "default_context" + name: "标准模板" + description: "标准的上下文格式化模板" + has_knowledge_base: true + content: | + 请根据以下参考资料回答用户问题。 + + 参考资料: + {{contexts}} + + 用户问题:{{query}} + + 请基于上述参考资料进行回答。如果参考资料不足以回答问题,请明确告知。 + + - id: "detailed_context" + name: "详细模板" + description: "包含详细说明的上下文模板" + has_knowledge_base: true + content: | + ## 任务说明 + 请根据提供的参考资料,准确、全面地回答用户问题。 + + ## 参考资料 + {{contexts}} + + ## 用户问题 + {{query}} + + ## 回答要求 + 1. 仅基于参考资料回答,不要编造信息 + 2. 如果多个资料有冲突,请综合分析 + 3. 适当引用来源,增强可信度 + 4. 如果资料不足,请明确说明 + + 当前时间:{{current_time}} {{current_week}} + + - id: "simple_context" + name: "简洁模板" + description: "简洁的上下文模板" + has_knowledge_base: true + content: | + 参考资料: + {{contexts}} + + 问题:{{query}} + + 请回答上述问题。 + + - id: "qa_context" + name: "问答模板" + description: "问答场景专用模板" + has_knowledge_base: true + content: | + 你需要回答一个问题。以下是可能相关的资料: + + {{contexts}} + + 用户的问题是:{{query}} + + 请基于以上资料回答问题。回答要求: + - 直接回答问题,不要重复问题 + - 如果资料中没有相关信息,请说明 + - 保持回答简洁准确 diff --git a/config/prompt_templates/fallback.yaml b/config/prompt_templates/fallback.yaml new file mode 100644 index 00000000..5f0e722a --- /dev/null +++ b/config/prompt_templates/fallback.yaml @@ -0,0 +1,47 @@ +# 兜底提示词模板 +templates: + - id: "default_fallback" + name: "标准兜底" + description: "标准的兜底回复模板" + content: | + 抱歉,我在知识库中没有找到与您问题直接相关的内容。 + + 您可以尝试: + 1. 换一种方式描述您的问题 + 2. 提供更多具体信息 + 3. 咨询相关领域的专业人员 + + 如果您有其他问题,我很乐意继续为您服务。 + + - id: "polite_fallback" + name: "礼貌兜底" + description: "更加礼貌友好的兜底回复" + content: | + 非常抱歉,目前我无法为您提供这个问题的准确答案。这可能是因为: + - 该问题超出了我的知识范围 + - 知识库中暂无相关内容 + + 建议您: + 1. 尝试用不同的关键词重新提问 + 2. 将问题拆分为更具体的小问题 + 3. 联系人工客服获取帮助 + + 感谢您的理解,期待能在其他问题上帮助到您! + + - id: "brief_fallback" + name: "简洁兜底" + description: "简短的兜底回复" + content: "抱歉,我暂时无法回答这个问题。请尝试换一种方式提问,或联系人工客服。" + + - id: "model_fallback" + name: "模型兜底" + description: "交给模型继续生成的兜底提示词" + content: | + 知识库中没有找到与用户问题直接相关的内容。请根据你的通用知识,尽可能帮助用户解答问题。 + + 注意事项: + 1. 明确告知用户这是基于通用知识的回答,而非知识库内容 + 2. 如果问题涉及特定领域或需要最新信息,建议用户查阅官方资料 + 3. 保持回答的准确性和客观性 + + 用户问题:{{query}} diff --git a/config/prompt_templates/rewrite_system.yaml b/config/prompt_templates/rewrite_system.yaml new file mode 100644 index 00000000..1c74e82e --- /dev/null +++ b/config/prompt_templates/rewrite_system.yaml @@ -0,0 +1,30 @@ +# 改写系统提示词模板 +templates: + - id: "default_rewrite_system" + name: "标准改写" + description: "标准的问题改写系统提示词" + content: | + 你是一个专业的问题改写助手。你的任务是将用户的后续问题改写为独立、完整的问题,使其可以脱离对话上下文独立理解。 + + 改写规则: + 1. 消解代词指代(如"它"、"这个"、"他们"等) + 2. 补全省略的主语或宾语 + 3. 保持原问题的核心意图不变 + 4. 改写后的问题应该简洁清晰 + + 只输出改写后的问题,不要输出其他内容。 + + - id: "strict_rewrite_system" + name: "严格改写" + description: "严格要求的问题改写模板" + content: | + 你是问题改写专家。请将用户问题改写为完整、独立的问题。 + + 严格要求: + 1. 必须消解所有代词和指代 + 2. 必须补全所有省略内容 + 3. 不得改变原问题意图 + 4. 不得添加原问题没有的内容 + 5. 改写结果必须是一个问句 + + 直接输出改写后的问题,不要有任何解释。 diff --git a/config/prompt_templates/rewrite_user.yaml b/config/prompt_templates/rewrite_user.yaml new file mode 100644 index 00000000..8605c1af --- /dev/null +++ b/config/prompt_templates/rewrite_user.yaml @@ -0,0 +1,30 @@ +# 改写用户提示词模板 +templates: + - id: "default_rewrite_user" + name: "标准格式" + description: "标准的改写用户提示词格式" + content: | + ## 历史对话背景 + {{conversation}} + + ## 需要改写的用户问题 + {{query}} + + ## 改写后的问题 + + - id: "detailed_rewrite_user" + name: "详细格式" + description: "详细的改写用户提示词格式" + content: | + ## 历史对话背景 + 以下是用户与助手的对话历史,请仔细阅读以理解上下文: + + {{conversation}} + + ## 当前用户问题 + {{query}} + + ## 任务要求 + 请根据以上对话历史,将当前问题改写为一个独立、完整、可以脱离上下文理解的问题。 + + ## 改写后的问题 diff --git a/config/prompt_templates/system_prompt.yaml b/config/prompt_templates/system_prompt.yaml new file mode 100644 index 00000000..3e3afded --- /dev/null +++ b/config/prompt_templates/system_prompt.yaml @@ -0,0 +1,113 @@ +# 系统提示词模板 +templates: + - id: "default_kb" + name: "知识库问答" + description: "基于知识库内容回答问题的标准模板" + has_knowledge_base: true + content: | + 你是一个专业的知识库问答助手。请根据提供的参考资料回答用户问题。 + + 要求: + 1. 仅基于参考资料回答,不要编造信息 + 2. 如果参考资料不足以回答问题,请明确告知用户 + 3. 回答要准确、简洁、专业 + 4. 适当引用来源,增强可信度 + + 当前时间:{{current_time}} + + - id: "expert_assistant" + name: "领域专家" + description: "专业领域深度解答的专家模板" + has_knowledge_base: true + content: | + 你是一位资深的领域专家助手,拥有丰富的专业知识和实践经验。 + + 核心职责: + 1. 深入分析用户问题,提供专业、全面的解答 + 2. 结合知识库内容,给出有据可依的建议 + 3. 必要时提供多角度分析和权衡利弊 + 4. 用通俗易懂的语言解释专业概念 + + 回答风格: + - 条理清晰,逻辑严谨 + - 重点突出,层次分明 + - 实用性强,可操作性高 + + 当前时间:{{current_time}} + + - id: "customer_service" + name: "客服助手" + description: "友善专业的客服对话模板" + has_knowledge_base: true + content: | + 你是一位专业、友善的客服助手,致力于为用户提供优质的服务体验。 + + 服务准则: + 1. 态度热情友好,用语礼貌得体 + 2. 准确理解用户需求,提供针对性解答 + 3. 基于知识库内容回答,确保信息准确 + 4. 遇到无法解答的问题,引导用户寻求其他帮助渠道 + + 回答要求: + - 语气亲切自然,避免机械生硬 + - 回答简洁明了,重点突出 + - 必要时主动提供相关信息 + + 当前时间:{{current_time}} + + - id: "technical_support" + name: "技术支持" + description: "技术问题诊断与解决方案模板" + has_knowledge_base: true + content: | + 你是一位专业的技术支持工程师,负责解答技术相关问题。 + + 工作职责: + 1. 准确诊断用户遇到的技术问题 + 2. 提供清晰、可执行的解决方案 + 3. 必要时提供代码示例或操作步骤 + 4. 解释技术原理,帮助用户理解 + + 回答规范: + - 技术术语准确,解释清晰 + - 步骤详细,便于操作 + - 代码示例规范,注释完整 + - 考虑不同场景和边界情况 + + 当前时间:{{current_time}} + + - id: "pure_chat" + name: "通用对话" + description: "无知识库的通用对话模板" + has_knowledge_base: false + content: | + 你是一个智能对话助手,可以与用户进行自然流畅的对话。 + + 特点: + 1. 理解用户意图,提供有帮助的回答 + 2. 知识广泛,可以讨论多种话题 + 3. 回答准确、客观、有见地 + 4. 语言自然,富有亲和力 + + 当前时间:{{current_time}} + + - id: "web_search_assistant" + name: "网络搜索助手" + description: "结合网络搜索的智能助手模板" + has_knowledge_base: true + has_web_search: true + content: | + 你是一个具备网络搜索能力的智能助手,可以获取最新信息来回答问题。 + + 工作方式: + 1. 结合网络搜索结果和知识库内容回答问题 + 2. 优先使用最新、最权威的信息来源 + 3. 明确标注信息来源,便于用户验证 + 4. 对于时效性强的问题,优先参考搜索结果 + + 注意事项: + - 区分事实和观点 + - 对比多个来源,提供全面视角 + - 标注信息的时效性 + + 当前时间:{{current_time}} diff --git a/docs/images/architecture.png b/docs/images/architecture.png index 3522ea5c..532bd99d 100644 Binary files a/docs/images/architecture.png and b/docs/images/architecture.png differ diff --git a/frontend/src/api/agent/index.ts b/frontend/src/api/agent/index.ts new file mode 100644 index 00000000..71254f59 --- /dev/null +++ b/frontend/src/api/agent/index.ts @@ -0,0 +1,163 @@ +import { get, post, put, del } from "../../utils/request"; + +// 智能体配置 +export interface CustomAgentConfig { + // ===== 基础设置 ===== + agent_mode?: 'quick-answer' | 'smart-reasoning'; // 运行模式:quick-answer=RAG模式, smart-reasoning=ReAct Agent模式 + system_prompt?: string; // 统一系统提示词(使用 {{web_search_status}} 占位符动态控制行为) + context_template?: string; // 上下文模板(普通模式) + + // ===== 模型设置 ===== + model_id?: string; + rerank_model_id?: string; // ReRank 模型 ID + temperature?: number; + max_completion_tokens?: number; // 最大生成token数(普通模式) + + // ===== Agent模式设置 ===== + 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[]; + + // ===== 网络搜索设置 ===== + web_search_enabled?: boolean; + web_search_max_results?: number; + + // ===== 多轮对话设置 ===== + multi_turn_enabled?: boolean; // 是否启用多轮对话 + history_turns?: number; // 保留历史轮数 + + // ===== 检索策略设置 ===== + embedding_top_k?: number; // 向量召回TopK + keyword_threshold?: number; // 关键词召回阈值 + vector_threshold?: number; // 向量召回阈值 + rerank_top_k?: number; // 重排TopK + rerank_threshold?: number; // 重排阈值 + + // ===== 高级设置(主要用于普通模式)===== + enable_query_expansion?: boolean; // 是否启用查询扩展 + enable_rewrite?: boolean; // 是否启用问题改写 + rewrite_prompt_system?: string; // 改写系统提示词 + rewrite_prompt_user?: string; // 改写用户提示词模板 + fallback_strategy?: 'fixed' | 'model'; // 兜底策略 + fallback_response?: string; // 固定兜底回复 + fallback_prompt?: string; // 兜底提示词(模型生成时) + + // ===== 已废弃字段(保留兼容)===== + welcome_message?: string; + suggested_prompts?: string[]; +} + +// 智能体 +export interface CustomAgent { + id: string; + name: string; + description?: string; + avatar?: string; + is_builtin: boolean; + tenant_id?: number; + created_by?: string; + config: CustomAgentConfig; + created_at?: string; + updated_at?: string; +} + +// 创建智能体请求 +export interface CreateAgentRequest { + name: string; + description?: string; + avatar?: string; + config?: CustomAgentConfig; +} + +// 更新智能体请求 +export interface UpdateAgentRequest { + name: string; + description?: string; + avatar?: string; + config?: CustomAgentConfig; +} + +// 内置智能体 ID +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() { + return get<{ data: CustomAgent[] }>('/api/v1/agents'); +} + +// 获取智能体详情 +export function getAgentById(id: string) { + return get<{ data: CustomAgent }>(`/api/v1/agents/${id}`); +} + +// 创建智能体 +export function createAgent(data: CreateAgentRequest) { + return post<{ data: CustomAgent }>('/api/v1/agents', data); +} + +// 更新智能体 +export function updateAgent(id: string, data: UpdateAgentRequest) { + return put<{ data: CustomAgent }>(`/api/v1/agents/${id}`, data); +} + +// 删除智能体 +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 (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/api/chat/streame.ts b/frontend/src/api/chat/streame.ts index 4b0ae712..f7dd5628 100644 --- a/frontend/src/api/chat/streame.ts +++ b/frontend/src/api/chat/streame.ts @@ -28,7 +28,7 @@ export function useStream() { let renderTimer: number | null = null // 启动流式请求 - const startStream = async (params: { session_id: any; query: any; knowledge_base_ids?: string[]; knowledge_ids?: string[]; agent_enabled?: boolean; web_search_enabled?: boolean; summary_model_id?: string; mcp_service_ids?: string[]; mentioned_items?: Array<{id: string; name: string; type: string; kb_type?: string}>; method: string; url: string }) => { + const startStream = async (params: { session_id: any; query: any; knowledge_base_ids?: string[]; knowledge_ids?: string[]; agent_enabled?: boolean; agent_id?: string; web_search_enabled?: boolean; summary_model_id?: string; mcp_service_ids?: string[]; mentioned_items?: Array<{id: string; name: string; type: string; kb_type?: string}>; method: string; url: string }) => { // 重置状态 output.value = ''; error.value = null; @@ -89,6 +89,10 @@ export function useStream() { if (params.knowledge_ids !== undefined && params.knowledge_ids.length > 0) { postBody.knowledge_ids = params.knowledge_ids; } + // Include agent_id if provided (for custom agent configuration) + if (params.agent_id) { + postBody.agent_id = params.agent_id; + } // Include web_search_enabled if provided if (params.web_search_enabled !== undefined) { postBody.web_search_enabled = params.web_search_enabled; diff --git a/frontend/src/api/system/index.ts b/frontend/src/api/system/index.ts index 134d18e5..9063b6f6 100644 --- a/frontend/src/api/system/index.ts +++ b/frontend/src/api/system/index.ts @@ -29,9 +29,7 @@ export interface AgentConfig { allowed_tools: string[] temperature: number knowledge_bases?: string[] - system_prompt_web_enabled?: string // Custom system prompt when web search is enabled - system_prompt_web_disabled?: string // Custom system prompt when web search is disabled - use_custom_system_prompt?: boolean + system_prompt?: string // Unified system prompt (uses {{web_search_status}} placeholder) available_tools?: ToolDefinition[] // GET 响应中包含,POST/PUT 不需要 available_placeholders?: PlaceholderDefinition[] // GET 响应中包含,POST/PUT 不需要 } @@ -41,8 +39,6 @@ export interface ConversationConfig { context_template: string temperature: number max_completion_tokens: number - use_custom_system_prompt?: boolean - use_custom_context_template?: boolean max_rounds: number embedding_top_k: number keyword_threshold: number @@ -60,6 +56,23 @@ export interface ConversationConfig { enable_query_expansion?: boolean } +export interface PromptTemplate { + id: string + name: string + description: string + content: string + has_knowledge_base?: boolean + has_web_search?: boolean +} + +export interface PromptTemplatesConfig { + system_prompt: PromptTemplate[] + context_template: PromptTemplate[] + rewrite_system: PromptTemplate[] + rewrite_user: PromptTemplate[] + fallback: PromptTemplate[] +} + export function getSystemInfo(): Promise<{ data: SystemInfo }> { return get('/api/v1/system/info') } @@ -79,3 +92,7 @@ export function getConversationConfig(): Promise<{ data: ConversationConfig }> { export function updateConversationConfig(config: ConversationConfig): Promise<{ data: ConversationConfig }> { return put('/api/v1/tenants/kv/conversation-config', config) } + +export function getPromptTemplates(): Promise<{ data: PromptTemplatesConfig }> { + return get('/api/v1/tenants/kv/prompt-templates') +} diff --git a/frontend/src/assets/img/agent-green.svg b/frontend/src/assets/img/agent-green.svg new file mode 100644 index 00000000..96b5b46c --- /dev/null +++ b/frontend/src/assets/img/agent-green.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/frontend/src/assets/img/agent.svg b/frontend/src/assets/img/agent.svg index 458f55da..3b94a604 100644 --- a/frontend/src/assets/img/agent.svg +++ b/frontend/src/assets/img/agent.svg @@ -1,5 +1,5 @@ - - - - \ No newline at end of file + + + + diff --git a/frontend/src/components/AgentAvatar.vue b/frontend/src/components/AgentAvatar.vue new file mode 100644 index 00000000..af91eb24 --- /dev/null +++ b/frontend/src/components/AgentAvatar.vue @@ -0,0 +1,160 @@ + + + + + diff --git a/frontend/src/components/AgentSelector.vue b/frontend/src/components/AgentSelector.vue new file mode 100644 index 00000000..17629a94 --- /dev/null +++ b/frontend/src/components/AgentSelector.vue @@ -0,0 +1,556 @@ + + + + + + + + diff --git a/frontend/src/components/Input-field.vue b/frontend/src/components/Input-field.vue index 28077bac..8ae035ff 100644 --- a/frontend/src/components/Input-field.vue +++ b/frontend/src/components/Input-field.vue @@ -9,8 +9,10 @@ import { listKnowledgeBases, searchKnowledge, batchQueryKnowledge } from '@/api/ import { stopSession } from '@/api/chat'; import KnowledgeBaseSelector from './KnowledgeBaseSelector.vue'; 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, 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'; @@ -19,6 +21,8 @@ const route = useRoute(); const router = useRouter(); const settingsStore = useSettingsStore(); const uiStore = useUIStore(); +const { t } = useI18n(); + let query = ref(""); const showKbSelector = ref(false); const atButtonRef = ref(); @@ -26,6 +30,110 @@ const showAgentModeSelector = ref(false); const agentModeButtonRef = ref(); const agentModeDropdownStyle = ref>({}); +// 智能体相关状态 +const agents = ref([]); +const selectedAgentId = computed({ + 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_QUICK_ANSWER_ID, + name: t('input.normalMode'), + is_builtin: true, + config: { agent_mode: 'quick-answer' as const } + } as CustomAgent; +}); + +// 判断是否为自定义智能体(非内置) +const isCustomAgent = computed(() => { + const agent = selectedAgent.value; + 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 (!hasAgentConfig.value) return []; + 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'; +}); + +// 智能体是否启用了网络搜索 +const agentWebSearchEnabled = computed(() => { + if (!hasAgentConfig.value) return null; // null 表示不受智能体控制 + return currentAgentConfig.value?.web_search_enabled ?? true; +}); + +// 网络搜索是否被智能体禁用(只读状态)- 只有明确设置为 false 时才禁用 +const isWebSearchDisabledByAgent = computed(() => { + return hasAgentConfig.value && agentWebSearchEnabled.value === false; +}); + +// 知识库选择是否被智能体锁定 +// 1. 如果智能体配置了 kb_selection_mode = 'none' → 完全禁用知识库 +// 其他情况用户都可以在允许的范围内通过 @ 选择知识库 +const isKnowledgeBaseLockedByAgent = computed(() => { + if (!hasAgentConfig.value) return false; + // 只有禁用了知识库才锁定 + return agentKBSelectionMode.value === 'none'; +}); + +// 知识库是否被智能体完全禁用(kb_selection_mode = 'none') +const isKnowledgeBaseDisabledByAgent = computed(() => { + if (!hasAgentConfig.value) return false; + return agentKBSelectionMode.value === 'none'; +}); + +// 智能体配置的模型 ID +const agentModelId = computed(() => { + if (!hasAgentConfig.value) return null; + return currentAgentConfig.value?.model_id || null; +}); + +// 模型选择是否被智能体锁定 +const isModelLockedByAgent = computed(() => { + return hasAgentConfig.value && !!agentModelId.value; +}); + // Mention related state const showMention = ref(false); const mentionQuery = ref(""); @@ -80,21 +188,35 @@ const selectedFiles = computed(() => { }); // 合并所有选中项(用于输入框内显示) + // 现在智能体配置的知识库也在 store 中,统一从 selectedKbs 获取 const allSelectedItems = computed(() => { - const kbs = selectedKbs.value.map(kb => ({ + // 获取智能体预配置的知识库 IDs(用于标记和排序) + const agentKbIds = agentKnowledgeBases.value; + + // 所有选中的知识库,标记是否为智能体配置 + const allKbs = selectedKbs.value.map(kb => ({ ...kb, type: 'kb' as const, - kbType: kb.type // 保留原始类型用于显示区分 + kbType: kb.type, + isAgentConfigured: agentKbIds.includes(kb.id) })); + + // 用户选择的文件 const files = selectedFiles.value.map((f: { id: string; name: string }) => ({ ...f, - type: 'file' as const + type: 'file' as const, + isAgentConfigured: false })); - return [...kbs, ...files]; + + // 智能体配置的放在前面 + const agentConfiguredKbs = allKbs.filter(kb => kb.isAgentConfigured); + const userSelectedKbs = allKbs.filter(kb => !kb.isAgentConfigured); + + return [...agentConfiguredKbs, ...userSelectedKbs, ...files]; }); -// 移除选中项 -const removeSelectedItem = (item: { id: string; type: 'kb' | 'file' }) => { +// 移除选中项(智能体配置的项也可以移除) +const removeSelectedItem = (item: { id: string; type: 'kb' | 'file'; isAgentConfigured?: boolean }) => { if (item.type === 'kb') { settingsStore.removeKnowledgeBase(item.id); } else { @@ -115,14 +237,21 @@ const showModelSelector = ref(false); const modelButtonRef = ref(); const modelDropdownStyle = ref>({}); -const { t } = useI18n(); - // 显示的知识库标签(最多显示2个) const displayedKbs = computed(() => selectedKbs.value.slice(0, 2)); const remainingCount = computed(() => Math.max(0, selectedKbs.value.length - 2)); // 根据不同状态组合计算输入框的 placeholder const inputPlaceholder = computed(() => { + // 如果选择了自定义智能体 + if (isCustomAgent.value && selectedAgent.value) { + // 有描述时显示描述,否则显示"向 [名称] 提问" + if (selectedAgent.value.description) { + return selectedAgent.value.description; + } + return t('input.placeholderAgent', { name: selectedAgent.value.name }); + } + const hasKnowledge = allSelectedItems.value.length > 0; const hasWebSearch = isWebSearchEnabled.value && isWebSearchConfigured.value; @@ -211,6 +340,16 @@ const loadWebSearchConfig = async () => { } }; +// 加载智能体列表 +const loadAgents = async () => { + try { + const response = await listAgents(); + agents.value = response.data || []; + } catch (error) { + console.error('Failed to load agents:', error); + } +}; + const loadConversationConfig = async () => { try { const response = await getConversationConfig(); @@ -432,10 +571,28 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) => mentionOffset.value = 0; } - // Fetch KBs (always show, filter by query) - only on first load + // 根据智能体的 kb_selection_mode 过滤知识库 let kbItems: any[] = []; if (!append) { - const kbs = knowledgeBases.value.filter(kb => + // 获取可选的知识库列表 + let availableKbs = knowledgeBases.value; + + // 如果智能体有配置,根据 kb_selection_mode 过滤 + if (hasAgentConfig.value) { + const kbMode = agentKBSelectionMode.value; + if (kbMode === 'none') { + // 不使用知识库,不显示任何知识库 + availableKbs = []; + } else if (kbMode === 'selected') { + // 仅显示智能体配置的知识库 + const configuredKbIds = agentKnowledgeBases.value; + availableKbs = knowledgeBases.value.filter(kb => configuredKbIds.includes(kb.id)); + } + // kbMode === 'all' 时显示全部知识库 + } + + // 按查询过滤 + const kbs = availableKbs.filter(kb => !q || kb.name.toLowerCase().includes(q.toLowerCase()) ); kbItems = kbs.map(kb => ({ @@ -448,26 +605,41 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) => } // Fetch Files from API + // 如果智能体禁用了知识库,也不显示文件 let fileItems: any[] = []; - mentionLoading.value = true; - try { - const res: any = await searchKnowledge(q || '', mentionOffset.value, MENTION_PAGE_SIZE); - console.log('[Mention] searchKnowledge response:', res); - if (res.data && Array.isArray(res.data)) { - fileItems = res.data.map((f: any) => ({ - id: f.id, - name: f.title || f.file_name, - type: 'file' as const, - kbName: f.knowledge_base_name || '' - })); + const shouldLoadFiles = !hasAgentConfig.value || agentKBSelectionMode.value !== 'none'; + + if (shouldLoadFiles) { + mentionLoading.value = true; + try { + const res: any = await searchKnowledge(q || '', mentionOffset.value, MENTION_PAGE_SIZE); + 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') { + const configuredKbIds = agentKnowledgeBases.value; + files = files.filter((f: any) => configuredKbIds.includes(f.knowledge_base_id)); + } + + fileItems = files.map((f: any) => ({ + id: f.id, + name: f.title || f.file_name, + type: 'file' as const, + kbName: f.knowledge_base_name || '' + })); + } + mentionHasMore.value = res.has_more || false; + mentionOffset.value += fileItems.length; + } catch (e) { + console.error('[Mention] searchKnowledge error:', e); + mentionHasMore.value = false; + } finally { + mentionLoading.value = false; } - mentionHasMore.value = res.has_more || false; - mentionOffset.value += fileItems.length; - } catch (e) { - console.error('[Mention] searchKnowledge error:', e); + } else { mentionHasMore.value = false; - } finally { - mentionLoading.value = false; } if (append) { @@ -556,6 +728,15 @@ const onInput = (val: string | InputEvent) => { } } else { if (textBeforeCursor.endsWith('@')) { + // 如果智能体禁用了知识库,不触发 @ 菜单 + if (isKnowledgeBaseDisabledByAgent.value) { + return; + } + // 如果智能体锁定了知识库且不允许用户选择,也不触发 @ 菜单 + if (isKnowledgeBaseLockedByAgent.value) { + return; + } + console.log('[Mention] @ detected, opening menu'); isMentionTriggeredByButton.value = false; mentionStartPos.value = cursor - 1; @@ -619,6 +800,13 @@ const onCompositionEnd = (e: CompositionEvent) => { }; const triggerMention = () => { + // 如果智能体锁定或禁用了知识库,不允许打开选择器 + if (isKnowledgeBaseLockedByAgent.value) { + const msgKey = isKnowledgeBaseDisabledByAgent.value ? 'input.kbDisabledByAgent' : 'input.kbLockedByAgent'; + MessagePlugin.warning(t(msgKey)); + return; + } + const textarea = getTextareaEl(); if (!textarea) return; @@ -712,6 +900,12 @@ const removeFile = (id: string) => { }; const toggleModelSelector = () => { + // 如果智能体锁定了模型,不允许打开选择器 + if (isModelLockedByAgent.value) { + MessagePlugin.warning(t('input.modelLockedByAgent')); + return; + } + // 互斥:关闭其他 showMention.value = false; showAgentModeSelector.value = false; @@ -761,6 +955,7 @@ onMounted(() => { loadWebSearchConfig(); loadConversationConfig(); loadChatModels(); + loadAgents(); // 如果从知识库内部进入,自动选中该知识库 const kbId = (route.params as any)?.kbId as string; @@ -931,18 +1126,14 @@ const updateAgentModeDropdownPosition = () => { }; const toggleAgentModeSelector = () => { - // 如果 Agent 未就绪,显示提示 - if (!settingsStore.isAgentReady && !isAgentEnabled.value) { - toggleAgentMode(); - return; - } - // 互斥 showMention.value = false; showModelSelector.value = false; showAgentModeSelector.value = !showAgentModeSelector.value; if (showAgentModeSelector.value) { + // 重新加载智能体列表 + loadAgents(); // 多次更新位置确保准确 nextTick(() => { updateAgentModeDropdownPosition(); @@ -956,21 +1147,82 @@ 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_SMART_REASONING_ID : BUILTIN_QUICK_ANSWER_ID); MessagePlugin.success(shouldEnableAgent ? t('input.messages.agentSwitchedOn') : t('input.messages.agentSwitchedOff')); } showAgentModeSelector.value = false; } +// 选择智能体(新版) +const handleSelectAgent = (agent: CustomAgent) => { + // 根据智能体的 agent_mode 判断是否为 Agent 模式 + const isAgentType = agent.config?.agent_mode === 'smart-reasoning'; + + // 内置智能体检查 - 从实际的智能体配置来判断 + 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) { + const agentWebSearch = agent.config?.web_search_enabled; + if (agentWebSearch !== undefined) { + // 智能体配置了网络搜索设置,同步到 store + settingsStore.toggleWebSearch(agentWebSearch); + } + + // 如果智能体配置了模型,同步到 store + const agentModel = agent.config?.model_id; + if (agentModel) { + selectedModelId.value = agentModel; + } + } + + showAgentModeSelector.value = false; + + const message = agent.is_builtin + ? (isAgentType ? t('input.messages.agentSwitchedOn') : t('input.messages.agentSwitchedOff')) + : t('input.messages.agentSelected', { name: agent.name }); + MessagePlugin.success(message); +} + const clearvalue = () => { query.value = ""; } @@ -1030,75 +1282,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 = () => { @@ -1107,6 +1409,12 @@ const toggleWebSearch = () => { showModelSelector.value = false; showAgentModeSelector.value = false; + // 如果智能体禁用了网络搜索,不允许开启 + if (isWebSearchDisabledByAgent.value) { + MessagePlugin.warning(t('input.webSearchDisabledByAgent')); + return; + } + if (!isWebSearchConfigured.value) { const messageContent = h('div', { style: 'display: flex; flex-direction: column; gap: 6px; max-width: 280px;' }, [ h('span', { style: 'color: #333; line-height: 1.5;' }, t('input.messages.webSearchNotConfigured')), @@ -1182,14 +1490,15 @@ onBeforeRouteUpdate((to, from, next) => {
- +
@@ -1238,33 +1547,14 @@ 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" > - - - - - {{ isAgentEnabled ? $t('input.agentMode') : $t('input.normalMode') }} + {{ selectedAgent.name || (isAgentEnabled ? $t('input.agentMode') : $t('input.normalMode')) }} {
- - -
-
-
-
- {{ $t('input.normalMode') }} - {{ $t('input.normalModeDesc') }} -
- - - -
-
-
- {{ $t('input.agentMode') }} - {{ $t('input.agentModeDesc') }} -
- - - -
- - - -
-
- -
-
-
+ + - +
{ - + + + {{ allSelectedItems.length > 0 ? $t('input.knowledgeBaseWithCount', { count: allSelectedItems.length }) : $t('input.knowledgeBase') }} +
@@ -1394,27 +1641,29 @@ onBeforeRouteUpdate((to, from, next) => { -
-
- - {{ selectedModel?.name || $t('input.notConfigured') }} - - +
+
- - + + {{ selectedModel?.name || $t('input.notConfigured') }} + + + + +
-
+
@@ -1609,6 +1858,12 @@ const getImgSrc = (url: string) => { background: rgba(0, 0, 0, 0.1); } } + + // 智能体配置的标签样式(用虚线边框区分,不显示锁图标) + &.agent-configured { + border-style: dashed; + opacity: 0.9; + } } :deep(.t-textarea__inner) { @@ -1711,46 +1966,63 @@ const getImgSrc = (url: string) => { 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); } } } @@ -1761,6 +2033,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); @@ -1788,6 +2080,19 @@ const getImgSrc = (url: string) => { background: rgba(16, 185, 129, 0.15); } } + + &.agent-controlled { + cursor: not-allowed; + opacity: 0.85; + + &:hover { + background: var(--td-bg-color-secondarycontainer, #f5f5f5); + } + + &.active:hover { + background: rgba(16, 185, 129, 0.1); + } + } } .kb-count { @@ -1826,6 +2131,7 @@ const getImgSrc = (url: string) => { display: flex; align-items: center; justify-content: center; + position: relative; &.active { background: rgba(16, 185, 129, 0.1); @@ -1852,24 +2158,44 @@ const getImgSrc = (url: string) => { } } } + + &.agent-controlled { + cursor: not-allowed; + opacity: 0.85; + + &:hover { + background: var(--td-bg-color-secondarycontainer, #f5f5f5); + } + + &.active:hover { + background: rgba(16, 185, 129, 0.1); + } + } } -:global(.websearch-tooltip-disabled) { +: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(.tooltip-with-link) { display: flex; flex-direction: column; - gap: 4px; + gap: 6px; max-width: 220px; font-size: 12px; - color: var(--td-text-color-secondary, #666); + color: var(--td-text-color-primary, #333); } -:global(.websearch-tooltip-disabled a) { +: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; } @@ -1956,6 +2282,18 @@ const getImgSrc = (url: string) => { align-items: center; margin-left: auto; flex-shrink: 0; + + &.agent-controlled { + .model-selector-trigger { + cursor: not-allowed; + opacity: 0.85; + + &:hover { + background: rgba(16, 185, 129, 0.1); + border-color: rgba(16, 185, 129, 0.3); + } + } + } } .model-selector-trigger { @@ -2040,12 +2378,12 @@ const getImgSrc = (url: string) => { display: flex; align-items: center; justify-content: space-between; - padding: 8px 10px; - border-bottom: 1px solid var(--td-component-border, #f2f4f5); - background: var(--td-bg-color-secondarycontainer, #fafcfc); + padding: 8px 12px; + border-bottom: 1px solid var(--td-component-stroke, #f0f0f0); + background: var(--td-bg-color-container, #fff); font-size: 12px; - font-weight: 600; - color: var(--td-text-color-primary, #222); + font-weight: 500; + color: var(--td-text-color-secondary, #666); } .model-selector-content { @@ -2061,26 +2399,26 @@ const getImgSrc = (url: string) => { display: inline-flex; align-items: center; gap: 4px; - padding: 3px 8px; - border-radius: 6px; - border: 1px solid var(--td-component-border, #e1e5e6); - background: var(--td-bg-color-container, #fff); - color: var(--td-text-color-secondary, #52575a); - font-size: 11px; + padding: 2px 8px; + border-radius: 4px; + border: 1px solid transparent; + background: transparent; + color: var(--td-brand-color, #07c05f); + font-size: 12px; font-weight: 500; cursor: pointer; - transition: all 0.12s; -} - -.model-selector-add .add-icon { - font-size: 12px; - line-height: 1; -} - -.model-selector-add:hover { - border-color: #10b981; - color: #10b981; - background: #f0fdf6; + transition: all 0.2s; + + .add-icon { + font-size: 14px; + line-height: 1; + font-weight: 400; + } + + &:hover { + color: var(--td-brand-color-hover, #05a04f); + background: var(--td-bg-color-secondarycontainer, #f3f3f3); + } } .model-option { diff --git a/frontend/src/components/PromptTemplateSelector.vue b/frontend/src/components/PromptTemplateSelector.vue new file mode 100644 index 00000000..99b202f4 --- /dev/null +++ b/frontend/src/components/PromptTemplateSelector.vue @@ -0,0 +1,261 @@ + + + + + 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
- +