feat: 统一系统提示词并优化智能体选择器界面

- 将系统提示词从分离的网络搜索开/关状态合并为统一提示词,使用 {{web_search_status}} 占位符动态控制行为
- 重构智能体选择器,从简单tooltip升级为内容丰富的popup,显示智能体详细信息、类型和能力
- 新增FAQ优先策略配置,支持FAQ答案优先于普通文档
- 优化知识库选择逻辑,智能体切换时自动同步配置的知识库
- 更新相关接口类型定义和国际化文本
This commit is contained in:
wizardchen
2025-12-28 21:46:42 +08:00
parent c9e482eb79
commit 6bc19ab082
21 changed files with 1198 additions and 609 deletions
+1 -2
View File
@@ -4,8 +4,7 @@ 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; // 系统提示词(普通模式,或Agent模式网络搜索关闭时)
system_prompt_web_enabled?: string; // Agent模式网络搜索开启时的系统提示词
system_prompt?: string; // 统一系统提示词(使用 {{web_search_status}} 占位符动态控制行为)
context_template?: string; // 上下文模板(普通模式)
// ===== 模型设置 =====
+1 -2
View File
@@ -29,8 +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
system_prompt?: string // Unified system prompt (uses {{web_search_status}} placeholder)
available_tools?: ToolDefinition[] // GET 响应中包含,POST/PUT 不需要
available_placeholders?: PlaceholderDefinition[] // GET 响应中包含,POST/PUT 不需要
}
+167 -43
View File
@@ -20,12 +20,13 @@
<!-- 内置智能体分组 -->
<div class="agent-group">
<div class="agent-group-title">{{ $t('agent.builtinAgents') }}</div>
<t-tooltip
<t-popup
v-for="agent in builtinAgents"
:key="agent.id"
:content="getAgentCapabilities(agent)"
:disabled="currentAgentId === agent.id"
placement="right"
trigger="hover"
:show-arrow="true"
:overlay-inner-class-name="'agent-tooltip-popup'"
>
<div
class="agent-option"
@@ -47,18 +48,39 @@
<path d="M13.5 4.5L6 12L2.5 8.5L3.5 7.5L6 10L12.5 3.5L13.5 4.5Z"/>
</svg>
</div>
</t-tooltip>
<template #content>
<div class="agent-tooltip-content">
<div class="agent-tooltip-header">
<div class="builtin-icon" :class="agent.config?.agent_mode === 'smart-reasoning' ? 'agent' : 'normal'">
<TIcon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'" size="14px" />
</div>
<div class="agent-tooltip-title">
<span class="agent-tooltip-name">{{ agent.name }}</span>
<span v-if="currentAgentId === agent.id" class="agent-tooltip-selected">{{ $t('agent.selector.current') }}</span>
</div>
</div>
<p class="agent-tooltip-desc">{{ agent.description || $t('agent.noDescription') }}</p>
<div class="agent-tooltip-capabilities">
<div class="capability-item">
<TIcon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'" size="12px" />
<span>{{ agent.config?.agent_mode === 'smart-reasoning' ? $t('agent.type.agent') : $t('agent.type.normal') }}</span>
</div>
</div>
</div>
</template>
</t-popup>
</div>
<!-- 自定义智能体分组 -->
<div v-if="customAgents.length > 0" class="agent-group">
<div class="agent-group-title">{{ $t('agent.customAgents') }}</div>
<t-tooltip
<t-popup
v-for="agent in customAgents"
:key="agent.id"
:content="getAgentCapabilities(agent)"
:disabled="currentAgentId === agent.id"
placement="right"
trigger="hover"
:show-arrow="true"
:overlay-inner-class-name="'agent-tooltip-popup'"
>
<div
class="agent-option"
@@ -78,7 +100,41 @@
<path d="M13.5 4.5L6 12L2.5 8.5L3.5 7.5L6 10L12.5 3.5L13.5 4.5Z"/>
</svg>
</div>
</t-tooltip>
<template #content>
<div class="agent-tooltip-content">
<div class="agent-tooltip-header">
<AgentAvatar :name="agent.name" size="small" />
<div class="agent-tooltip-title">
<span class="agent-tooltip-name">{{ agent.name }}</span>
<span v-if="currentAgentId === agent.id" class="agent-tooltip-selected">{{ $t('agent.selector.current') }}</span>
</div>
</div>
<p class="agent-tooltip-desc">{{ agent.description || $t('agent.noDescription') }}</p>
<div class="agent-tooltip-capabilities">
<div class="capability-item">
<TIcon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'" size="12px" />
<span>{{ agent.config?.agent_mode === 'smart-reasoning' ? $t('agent.type.agent') : $t('agent.type.normal') }}</span>
</div>
<div v-if="getKbCapability(agent)" class="capability-item">
<TIcon name="folder" size="12px" />
<span>{{ getKbCapability(agent) }}</span>
</div>
<div v-if="agent.config?.web_search_enabled" class="capability-item">
<TIcon name="internet" size="12px" />
<span>{{ $t('agent.capabilities.webSearchOn') }}</span>
</div>
<div v-if="agent.config?.mcp_services?.length || agent.config?.mcp_selection_mode === 'all'" class="capability-item">
<TIcon name="extension" size="12px" />
<span>{{ $t('agent.capabilities.mcpEnabled') }}</span>
</div>
<div v-if="agent.config?.multi_turn_enabled" class="capability-item">
<TIcon name="chat-bubble" size="12px" />
<span>{{ $t('agent.capabilities.multiTurn') }}</span>
</div>
</div>
</div>
</template>
</t-popup>
</div>
<!-- 空状态 -->
@@ -94,7 +150,7 @@
<script setup lang="ts">
import { ref, computed, watch, onMounted, nextTick } from 'vue';
import { useI18n } from 'vue-i18n';
import { Icon as TIcon } from 'tdesign-vue-next';
import { Icon as TIcon, Popup as TPopup } from 'tdesign-vue-next';
import { listAgents, type CustomAgent, BUILTIN_QUICK_ANSWER_ID, BUILTIN_SMART_REASONING_ID } from '@/api/agent';
import AgentAvatar from '@/components/AgentAvatar.vue';
@@ -139,45 +195,17 @@ const customAgents = computed(() => {
return agents.value.filter(a => !a.is_builtin);
});
// 获取智能体能力描述(用于 tooltip)
const getAgentCapabilities = (agent: CustomAgent): string => {
// 内置智能体
if (agent.is_builtin) {
if (agent.config?.agent_mode === 'quick-answer') {
return t('agent.capabilities.normal');
} else if (agent.config?.agent_mode === 'smart-reasoning') {
return t('agent.capabilities.agent');
}
return '';
}
// 自定义智能体
const capabilities: string[] = [];
// 获取知识库能力描述
const getKbCapability = (agent: CustomAgent): string => {
const config = agent.config || {};
if (config.model_id) {
capabilities.push(t('agent.capabilities.modelSpecified'));
}
if (config.kb_selection_mode === 'none') {
capabilities.push(t('agent.capabilities.kbDisabled'));
return '';
} else if (config.knowledge_bases && config.knowledge_bases.length > 0) {
capabilities.push(t('agent.capabilities.kbCount', { count: config.knowledge_bases.length }));
return t('agent.capabilities.kbCount', { count: config.knowledge_bases.length });
} else if (config.kb_selection_mode === 'all') {
capabilities.push(t('agent.capabilities.kbAll'));
return t('agent.capabilities.kbAll');
}
if (config.rerank_model_id) {
capabilities.push(t('agent.capabilities.rerankSpecified'));
}
if (config.web_search_enabled === true) {
capabilities.push(t('agent.capabilities.webSearchOn'));
} else if (config.web_search_enabled === false) {
capabilities.push(t('agent.capabilities.webSearchOff'));
}
if (config.system_prompt) {
capabilities.push(t('agent.capabilities.hasPrompt'));
}
return capabilities.length > 0 ? capabilities.join('、') : t('agent.capabilities.default');
return '';
};
// 加载智能体列表
@@ -429,4 +457,100 @@ onMounted(() => {
flex-shrink: 0;
margin-left: 6px;
}
// Tooltip 内容样式
.agent-tooltip-content {
padding: 4px 0;
min-width: 200px;
max-width: 280px;
}
.agent-tooltip-header {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
.builtin-icon {
width: 28px;
height: 28px;
}
}
.agent-tooltip-title {
display: flex;
flex-direction: column;
gap: 2px;
flex: 1;
min-width: 0;
}
.agent-tooltip-name {
font-size: 13px;
font-weight: 600;
color: var(--td-text-color-primary, #222);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.agent-tooltip-selected {
font-size: 10px;
color: #10b981;
font-weight: 500;
}
.agent-tooltip-desc {
font-size: 12px;
color: var(--td-text-color-secondary, #666);
line-height: 1.5;
margin: 0 0 10px 0;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.agent-tooltip-capabilities {
display: flex;
flex-wrap: wrap;
gap: 6px;
padding-top: 8px;
border-top: 1px solid var(--td-component-stroke, #f0f0f0);
}
.capability-item {
display: inline-flex;
align-items: center;
gap: 4px;
padding: 3px 8px;
background: var(--td-bg-color-secondarycontainer, #f5f5f5);
border-radius: 4px;
font-size: 11px;
color: var(--td-text-color-secondary, #666);
:deep(.t-icon) {
color: var(--td-text-color-placeholder, #999);
}
}
</style>
<!-- 全局样式覆盖 TDesign Popup -->
<style lang="less">
.agent-tooltip-popup {
&.t-popup__content {
background: var(--td-bg-color-container, #fff) !important;
border: 1px solid var(--td-component-border, #e7e9eb) !important;
border-radius: 8px !important;
box-shadow: var(--td-shadow-2, 0 6px 28px rgba(15, 23, 42, 0.08)) !important;
padding: 10px 12px !important;
}
.t-popup__arrow {
&::before {
background: var(--td-bg-color-container, #fff) !important;
border-color: var(--td-component-border, #e7e9eb) !important;
}
}
}
</style>
+29 -31
View File
@@ -21,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<HTMLElement>();
@@ -76,6 +78,19 @@ const agentKnowledgeBases = computed(() => {
return currentAgentConfig.value?.knowledge_bases || [];
});
// 当智能体改变时,将智能体配置的知识库同步到 store
// 这样用户可以移除这些知识库
watch([selectedAgentId, agentKnowledgeBases], ([newAgentId, newAgentKbs], [oldAgentId]) => {
if (newAgentId !== oldAgentId && newAgentKbs && newAgentKbs.length > 0) {
// 智能体切换了,将新智能体配置的知识库添加到 store
const currentSelected = settingsStore.settings.selectedKnowledgeBases || [];
const toAdd = newAgentKbs.filter((id: string) => !currentSelected.includes(id));
if (toAdd.length > 0) {
settingsStore.selectKnowledgeBases([...currentSelected, ...toAdd]);
}
}
}, { immediate: true });
// 智能体的知识库选择模式
const agentKBSelectionMode = computed(() => {
if (!hasAgentConfig.value) return null; // null 表示不受智能体控制
@@ -173,30 +188,18 @@ const selectedFiles = computed(() => {
});
// 合并所有选中项(用于输入框内显示)
// 包括用户选择的和智能体预配置的知识库
// 现在智能体配置的知识库也在 store 中,统一从 selectedKbs 获取
const allSelectedItems = computed(() => {
// 获取智能体预配置的知识库 IDs
// 获取智能体预配置的知识库 IDs(用于标记和排序)
const agentKbIds = agentKnowledgeBases.value;
// 用户选择的知识库(排除智能体已配置的)
const userSelectedKbs = selectedKbs.value
.filter(kb => !agentKbIds.includes(kb.id))
.map(kb => ({
...kb,
type: 'kb' as const,
kbType: kb.type,
isAgentConfigured: false
}));
// 智能体预配置的知识库
const agentConfiguredKbs = knowledgeBases.value
.filter(kb => agentKbIds.includes(kb.id))
.map(kb => ({
...kb,
type: 'kb' as const,
kbType: kb.type,
isAgentConfigured: true // 标记为智能体配置,不可删除
}));
// 所有选中的知识库,标记是否为智能体配置
const allKbs = selectedKbs.value.map(kb => ({
...kb,
type: 'kb' as const,
kbType: kb.type,
isAgentConfigured: agentKbIds.includes(kb.id)
}));
// 用户选择的文件
const files = selectedFiles.value.map((f: { id: string; name: string }) => ({
@@ -206,16 +209,14 @@ const selectedFiles = computed(() => {
}));
// 智能体配置的放在前面
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'; isAgentConfigured?: boolean }) => {
// 如果是智能体配置的,不允许删除
if (item.isAgentConfigured) {
MessagePlugin.warning(t('input.cannotRemoveAgentKb'));
return;
}
if (item.type === 'kb') {
settingsStore.removeKnowledgeBase(item.id);
} else {
@@ -236,8 +237,6 @@ const showModelSelector = ref(false);
const modelButtonRef = ref<HTMLElement>();
const modelDropdownStyle = ref<Record<string, string>>({});
const { t } = useI18n();
// 显示的知识库标签(最多显示2个)
const displayedKbs = computed(() => selectedKbs.value.slice(0, 2));
const remainingCount = computed(() => Math.max(0, selectedKbs.value.length - 2));
@@ -1507,8 +1506,7 @@ onBeforeRouteUpdate((to, from, next) => {
<t-icon v-else name="file" />
</span>
<span class="tag-name">{{ item.name }}</span>
<!-- 智能体配置的项不显示删除按钮 -->
<span v-if="!item.isAgentConfigured" class="tag-remove" @click="removeSelectedItem(item)">×</span>
<span class="tag-remove" @click="removeSelectedItem(item)">×</span>
</span>
</div>
+38 -5
View File
@@ -228,6 +228,8 @@ export default {
webSearchOff: 'Web search disabled',
hasPrompt: 'Custom prompt',
default: 'Default configuration',
mcpEnabled: 'MCP services enabled',
multiTurn: 'Multi-turn conversation',
},
type: {
normal: 'Quick Answer',
@@ -285,6 +287,12 @@ export default {
systemPromptRequired: 'System prompt is required',
modelRequired: 'Please select a model',
rerankModelRequired: 'ReRank model is required when using knowledge bases',
contextsMissing: 'Context template must contain {{contexts}} placeholder when knowledge base is enabled',
queryMissingInContext: 'Context template must contain {{query}} placeholder',
knowledgeBasesMissing: 'It is recommended to include {{knowledge_bases}} placeholder in system prompt so the model knows available knowledge bases',
queryMissingInRewrite: 'Rewrite user prompt must contain {{query}} placeholder',
conversationMissing: 'Rewrite user prompt must contain {{conversation}} placeholder',
queryMissingInFallback: 'Fallback prompt must contain {{query}} placeholder',
avatar: 'Avatar',
avatarPlaceholder: 'Enter Emoji or select',
description: 'Description',
@@ -295,8 +303,7 @@ export default {
model: 'Model',
modelPlaceholder: 'Select Model',
systemPrompt: 'System Prompt',
systemPromptPlaceholder: 'Custom system prompt to define agent behavior and role',
systemPromptWebEnabledPlaceholder: 'System prompt used when web search is enabled',
systemPromptPlaceholder: 'Custom system prompt to define agent behavior and role (use {{web_search_status}} placeholder for dynamic web search behavior)',
defaultPromptHint: 'Leave empty to use the following default system prompt:',
defaultContextTemplateHint: 'Leave empty to use the following default context template:',
contextTemplateRequired: 'Context template is required',
@@ -360,6 +367,34 @@ export default {
builtinSection: 'Built-in Agents',
customSection: 'My Agents',
addNew: 'Add New Agent',
current: 'Current',
},
// Built-in agent information
builtinInfo: {
quickAnswer: {
name: 'Quick Answer',
description: 'Knowledge base RAG Q&A for fast and accurate answers',
},
smartReasoning: {
name: 'Smart Reasoning',
description: 'ReAct reasoning framework with multi-step thinking and tool calling',
},
deepResearcher: {
name: 'Deep Researcher',
description: 'Focused on in-depth research and comprehensive analysis, capable of creating research plans, multi-dimensional information retrieval, deep thinking and providing thorough analysis reports',
},
dataAnalyst: {
name: 'Data Analyst',
description: 'Focused on database queries and data analysis, capable of understanding business needs, building SQL queries, analyzing data and providing insights',
},
knowledgeGraphExpert: {
name: 'Knowledge Graph Expert',
description: 'Focused on knowledge graph queries and relationship analysis, capable of exploring entity relationships, discovering hidden connections and building knowledge networks',
},
documentAssistant: {
name: 'Document Assistant',
description: 'Focused on document retrieval and content organization, capable of quickly locating documents, extracting key information and generating summaries',
},
},
},
settings: {
@@ -1706,9 +1741,7 @@ export default {
custom: 'Custom Prompt',
disabledHint: 'Currently using the default prompt. Enable custom to apply the content below.',
placeholder: 'Enter the system prompt, or leave blank to use the default...',
tabHint: 'Configure separate prompts for sessions with web search on or off.',
tabWebOn: 'Web search enabled',
tabWebOff: 'Web search disabled'
tabHint: 'Unified system prompt using {{web_search_status}} placeholder for dynamic web search behavior'
},
reset: {
header: 'Reset to Default Prompt',
+38 -5
View File
@@ -758,6 +758,8 @@ export default {
webSearchOff: "禁用网络搜索",
hasPrompt: "自定义提示词",
default: "默认配置",
mcpEnabled: "启用 MCP 服务",
multiTurn: "多轮对话",
},
type: {
normal: "快速问答",
@@ -815,6 +817,12 @@ export default {
systemPromptRequired: "请输入系统提示词",
modelRequired: "请选择模型",
rerankModelRequired: "使用知识库时请选择 ReRank 模型",
contextsMissing: "开启知识库时,上下文模板必须包含 {{contexts}} 占位符",
queryMissingInContext: "上下文模板必须包含 {{query}} 占位符",
knowledgeBasesMissing: "建议在系统提示词中包含 {{knowledge_bases}} 占位符,以便模型了解可用的知识库",
queryMissingInRewrite: "改写用户提示词必须包含 {{query}} 占位符",
conversationMissing: "改写用户提示词必须包含 {{conversation}} 占位符",
queryMissingInFallback: "兜底提示词必须包含 {{query}} 占位符",
avatar: "图标",
avatarPlaceholder: "输入 Emoji 或点击选择",
description: "描述",
@@ -825,8 +833,7 @@ export default {
model: "模型",
modelPlaceholder: "请选择模型",
systemPrompt: "系统提示词",
systemPromptPlaceholder: "自定义系统提示词,定义智能体的行为和角色",
systemPromptWebEnabledPlaceholder: "网络搜索开启时使用的系统提示词",
systemPromptPlaceholder: "自定义系统提示词,定义智能体的行为和角色(使用 {{web_search_status}} 占位符动态控制网络搜索行为)",
defaultPromptHint: "留空将使用以下系统默认提示词:",
defaultContextTemplateHint: "留空将使用以下系统默认上下文模板:",
contextTemplateRequired: "请输入上下文模板",
@@ -890,6 +897,34 @@ export default {
builtinSection: "内置智能体",
customSection: "我的智能体",
addNew: "添加新智能体",
current: "当前",
},
// 内置智能体信息
builtinInfo: {
quickAnswer: {
name: "快速问答",
description: "基于知识库的 RAG 问答,快速准确地回答问题",
},
smartReasoning: {
name: "智能推理",
description: "ReAct 推理框架,支持多步思考和工具调用",
},
deepResearcher: {
name: "深度研究员",
description: "专注于深度研究和综合分析,能够制定研究计划、多维度检索信息、深入思考并给出全面的分析报告",
},
dataAnalyst: {
name: "数据分析师",
description: "专注于数据库查询和数据分析,能够理解业务需求、构建SQL查询、分析数据并提供洞察",
},
knowledgeGraphExpert: {
name: "知识图谱专家",
description: "专注于知识图谱查询和关系分析,能够探索实体关系、发现隐藏联系并构建知识网络",
},
documentAssistant: {
name: "文档助手",
description: "专注于文档检索和内容整理,能够快速定位文档、提取关键信息并生成摘要",
},
},
},
file: {
@@ -1709,9 +1744,7 @@ export default {
custom: "自定义 Prompt",
disabledHint: "当前使用系统默认 Prompt,开启自定义后才会应用下方内容。",
placeholder: "请输入系统 Prompt,或留空使用默认 Prompt...",
tabHint: "根据是否启用网络搜索分别配置系统 Prompt。",
tabWebOn: "网络搜索已启用",
tabWebOff: "网络搜索未启用",
tabHint: "统一的系统提示词,使用 {{web_search_status}} 占位符动态控制网络搜索行为",
},
reset: {
header: "恢复默认 Prompt",
+8 -4
View File
@@ -22,8 +22,7 @@ interface AgentConfig {
maxIterations: number;
temperature: number;
allowedTools: string[];
system_prompt_web_enabled?: string;
system_prompt_web_disabled?: string;
system_prompt?: string; // Unified system prompt (uses {{web_search_status}} placeholder)
}
interface ConversationModels {
@@ -69,8 +68,7 @@ const defaultSettings: Settings = {
maxIterations: 5,
temperature: 0.7,
allowedTools: [], // 默认为空,需要通过 API 从后端加载
system_prompt_web_enabled: "",
system_prompt_web_disabled: "",
system_prompt: "",
},
selectedKnowledgeBases: [], // 默认为空数组
selectedFiles: [], // 默认为空数组
@@ -326,6 +324,12 @@ export const useSettingsStore = defineStore("settings", {
this.settings.isAgentEnabled = true;
}
// 自定义智能体需要根据其配置来决定
// 切换智能体时重置知识库和文件选择状态
// 因为不同智能体关联的知识库不同,需要清空用户之前的选择
this.settings.selectedKnowledgeBases = [];
this.settings.selectedFiles = [];
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
},
+339 -180
View File
@@ -127,44 +127,22 @@
</div>
</div>
<div class="setting-control setting-control-full" style="position: relative;">
<!-- Agent模式:网络搜索开/关两个提示词 -->
<div v-if="isAgentMode" class="system-prompt-tabs">
<t-tabs v-model="activePromptTab" class="prompt-variant-tabs">
<t-tab-panel value="web-disabled" label="网络搜索关闭">
<div class="textarea-with-template">
<t-textarea
ref="promptTextareaRef"
v-model="formData.config.system_prompt"
:placeholder="systemPromptWebDisabledPlaceholder"
:autosize="{ minRows: 10, maxRows: 25 }"
@input="handlePromptInput"
class="system-prompt-textarea"
/>
<PromptTemplateSelector
type="systemPrompt"
position="corner"
:hasKnowledgeBase="hasKnowledgeBase"
@select="handleSystemPromptTemplateSelect"
/>
</div>
</t-tab-panel>
<t-tab-panel value="web-enabled" label="网络搜索开启">
<div class="textarea-with-template">
<t-textarea
v-model="formData.config.system_prompt_web_enabled"
:placeholder="systemPromptWebEnabledPlaceholder"
:autosize="{ minRows: 10, maxRows: 25 }"
class="system-prompt-textarea"
/>
<PromptTemplateSelector
type="systemPrompt"
position="corner"
:hasKnowledgeBase="hasKnowledgeBase"
@select="handleSystemPromptTemplateSelect"
/>
</div>
</t-tab-panel>
</t-tabs>
<!-- Agent模式:统一提示词(使用 {{web_search_status}} 占位符动态控制行为) -->
<div v-if="isAgentMode" class="textarea-with-template">
<t-textarea
ref="promptTextareaRef"
v-model="formData.config.system_prompt"
:placeholder="systemPromptPlaceholder"
:autosize="{ minRows: 10, maxRows: 25 }"
@input="handlePromptInput"
class="system-prompt-textarea"
/>
<PromptTemplateSelector
type="systemPrompt"
position="corner"
:hasKnowledgeBase="hasKnowledgeBase"
@select="handleSystemPromptTemplateSelect"
/>
</div>
<!-- 普通模式:单个提示词 -->
<div v-else class="textarea-with-template">
@@ -625,8 +603,16 @@
v-for="kb in kbOptions"
:key="kb.value"
:value="kb.value"
:label="kb.label"
/>
:label="kb.label"
>
<div class="kb-option-item">
<span class="kb-option-icon" :class="kb.type === 'faq' ? 'faq-icon' : 'doc-icon'">
<t-icon :name="kb.type === 'faq' ? 'chat-bubble-help' : 'folder'" />
</span>
<span class="kb-option-label">{{ kb.label }}</span>
<span class="kb-option-count">({{ kb.count || 0 }})</span>
</div>
</t-option>
</t-select>
</div>
</div>
@@ -648,6 +634,56 @@
/>
</div>
</div>
<!-- FAQ 策略设置(仅当选择了 FAQ 类型知识库时显示) -->
<div v-if="hasFaqKnowledgeBase" class="faq-strategy-section">
<div class="faq-strategy-header">
<t-icon name="chat-bubble-help" class="faq-icon" />
<span>FAQ 优先策略</span>
<t-tooltip content="当知识库中包含 FAQ(问答对)时,可以启用此策略让 FAQ 答案优先于普通文档">
<t-icon name="help-circle" class="help-icon" />
</t-tooltip>
</div>
<!-- FAQ 优先开关 -->
<div class="setting-row">
<div class="setting-info">
<label>启用 FAQ 优先</label>
<p class="desc">FAQ 答案将优先于普通文档被引用,提高回答准确性</p>
</div>
<div class="setting-control">
<t-switch v-model="formData.config.faq_priority_enabled" />
</div>
</div>
<!-- FAQ 直接回答阈值 -->
<div v-if="formData.config.faq_priority_enabled" class="setting-row">
<div class="setting-info">
<label>直接回答阈值</label>
<p class="desc">当问题与 FAQ 相似度超过此值时,直接使用 FAQ 答案</p>
</div>
<div class="setting-control">
<div class="slider-wrapper">
<t-slider v-model="formData.config.faq_direct_answer_threshold" :min="0.7" :max="1" :step="0.05" />
<span class="slider-value">{{ formData.config.faq_direct_answer_threshold?.toFixed(2) }}</span>
</div>
</div>
</div>
<!-- FAQ 分数加权 -->
<div v-if="formData.config.faq_priority_enabled" class="setting-row">
<div class="setting-info">
<label>FAQ 分数加权</label>
<p class="desc">FAQ 结果的相关性分数乘以此系数,使其排序更靠前</p>
</div>
<div class="setting-control">
<div class="slider-wrapper">
<t-slider v-model="formData.config.faq_score_boost" :min="1" :max="2" :step="0.1" />
<span class="slider-value">{{ formData.config.faq_score_boost?.toFixed(1) }}x</span>
</div>
</div>
</div>
</div>
</div>
</div>
@@ -768,115 +804,107 @@
</div>
</div>
</div>
</div>
</div>
<!-- 高级设置(仅普通模式) -->
<div v-show="currentSection === 'advanced' && !isAgentMode" class="section">
<div class="section-header">
<h2>{{ $t('agent.editor.advancedSettings') || '高级设置' }}</h2>
<p class="section-description">配置兜底策略</p>
</div>
<div class="settings-group">
<!-- 兜底策略 -->
<div class="setting-row">
<div class="setting-info">
<label>{{ $t('agent.editor.fallbackStrategy') || '兜底策略' }}</label>
<p class="desc">当无法从知识库找到相关内容时的处理方式</p>
</div>
<div class="setting-control">
<t-radio-group v-model="formData.config.fallback_strategy">
<t-radio-button value="fixed">固定回复</t-radio-button>
<t-radio-button value="model">模型生成</t-radio-button>
</t-radio-group>
</div>
</div>
<!-- 固定兜底回复 -->
<div v-if="formData.config.fallback_strategy === 'fixed'" class="setting-row setting-row-vertical">
<div class="setting-info">
<label>{{ $t('agent.editor.fallbackResponse') || '固定回复内容' }}</label>
<p class="desc">当无法回答时返回的固定文本</p>
</div>
<div class="setting-control setting-control-full">
<div class="textarea-with-template">
<t-textarea
v-model="formData.config.fallback_response"
:placeholder="defaultFallbackResponse || $t('agent.editor.fallbackResponsePlaceholder') || '抱歉,我无法回答这个问题。'"
:autosize="{ minRows: 2, maxRows: 6 }"
/>
<PromptTemplateSelector
type="fallback"
position="corner"
@select="handleFallbackResponseTemplateSelect"
/>
<!-- 兜底策略(仅普通模式) -->
<template v-if="!isAgentMode">
<div class="setting-row">
<div class="setting-info">
<label>{{ $t('agent.editor.fallbackStrategy') || '兜底策略' }}</label>
<p class="desc">当无法从知识库找到相关内容时的处理方式</p>
</div>
<div class="setting-control">
<t-radio-group v-model="formData.config.fallback_strategy">
<t-radio-button value="fixed">固定回复</t-radio-button>
<t-radio-button value="model">模型生成</t-radio-button>
</t-radio-group>
</div>
</div>
</div>
<!-- 兜底提示词 -->
<div v-if="formData.config.fallback_strategy === 'model'" class="setting-row setting-row-vertical">
<div class="setting-info">
<label>{{ $t('agent.editor.fallbackPrompt') || '兜底提示词' }}</label>
<p class="desc">当无法从知识库找到答案时,引导模型生成回复的提示词</p>
<div class="placeholder-tags" v-if="fallbackPlaceholders.length > 0">
<span class="placeholder-label">可用变量:</span>
<t-tooltip
v-for="placeholder in fallbackPlaceholders"
:key="placeholder.name"
:content="placeholder.description + '(点击插入)'"
placement="top"
>
<span
class="placeholder-tag"
@click="handlePlaceholderClick('fallback', placeholder.name)"
v-text="'{{' + placeholder.name + '}}'"
></span>
</t-tooltip>
<span class="placeholder-hint" v-text="'(点击插入,或输入 {{ 唤起列表)'"></span>
<!-- 固定兜底回复 -->
<div v-if="formData.config.fallback_strategy === 'fixed'" class="setting-row setting-row-vertical">
<div class="setting-info">
<label>{{ $t('agent.editor.fallbackResponse') || '固定回复内容' }}</label>
<p class="desc">当无法回答时返回的固定文本</p>
</div>
<div class="setting-control setting-control-full">
<div class="textarea-with-template">
<t-textarea
v-model="formData.config.fallback_response"
:placeholder="defaultFallbackResponse || $t('agent.editor.fallbackResponsePlaceholder') || '抱歉,我无法回答这个问题。'"
:autosize="{ minRows: 2, maxRows: 6 }"
/>
<PromptTemplateSelector
type="fallback"
position="corner"
@select="handleFallbackResponseTemplateSelect"
/>
</div>
</div>
</div>
<div class="setting-control setting-control-full" style="position: relative;">
<div class="textarea-with-template">
<t-textarea
ref="fallbackPromptTextareaRef"
v-model="formData.config.fallback_prompt"
:placeholder="defaultFallbackPrompt || $t('agent.editor.fallbackPromptPlaceholder') || '留空使用系统默认提示词'"
:autosize="{ minRows: 4, maxRows: 10 }"
@input="handleFallbackPromptInput"
/>
<PromptTemplateSelector
type="fallback"
position="corner"
@select="handleFallbackPromptTemplateSelect"
/>
<!-- 兜底提示词 -->
<div v-if="formData.config.fallback_strategy === 'model'" class="setting-row setting-row-vertical">
<div class="setting-info">
<label>{{ $t('agent.editor.fallbackPrompt') || '兜底提示词' }}</label>
<p class="desc">当无法从知识库找到答案时,引导模型生成回复的提示词</p>
<div class="placeholder-tags" v-if="fallbackPlaceholders.length > 0">
<span class="placeholder-label">可用变量:</span>
<t-tooltip
v-for="placeholder in fallbackPlaceholders"
:key="placeholder.name"
:content="placeholder.description + '(点击插入)'"
placement="top"
>
<span
class="placeholder-tag"
@click="handlePlaceholderClick('fallback', placeholder.name)"
v-text="'{{' + placeholder.name + '}}'"
></span>
</t-tooltip>
<span class="placeholder-hint" v-text="'(点击插入,或输入 {{ 唤起列表)'"></span>
</div>
</div>
<Teleport to="body">
<div
v-if="fallbackPromptPopup.show && filteredFallbackPlaceholders.length > 0"
class="placeholder-popup-wrapper"
:style="fallbackPromptPopup.style"
>
<div class="placeholder-popup">
<div
v-for="(placeholder, index) in filteredFallbackPlaceholders"
:key="placeholder.name"
class="placeholder-item"
:class="{ active: fallbackPromptPopup.selectedIndex === index }"
@mousedown.prevent="insertGenericPlaceholder('fallback', placeholder.name, true)"
@mouseenter="fallbackPromptPopup.selectedIndex = index"
>
<div class="placeholder-name">
<code v-html="`{{${placeholder.name}}}`"></code>
<div class="setting-control setting-control-full" style="position: relative;">
<div class="textarea-with-template">
<t-textarea
ref="fallbackPromptTextareaRef"
v-model="formData.config.fallback_prompt"
:placeholder="defaultFallbackPrompt || $t('agent.editor.fallbackPromptPlaceholder') || '留空使用系统默认提示词'"
:autosize="{ minRows: 4, maxRows: 10 }"
@input="handleFallbackPromptInput"
/>
<PromptTemplateSelector
type="fallback"
position="corner"
@select="handleFallbackPromptTemplateSelect"
/>
</div>
<Teleport to="body">
<div
v-if="fallbackPromptPopup.show && filteredFallbackPlaceholders.length > 0"
class="placeholder-popup-wrapper"
:style="fallbackPromptPopup.style"
>
<div class="placeholder-popup">
<div
v-for="(placeholder, index) in filteredFallbackPlaceholders"
:key="placeholder.name"
class="placeholder-item"
:class="{ active: fallbackPromptPopup.selectedIndex === index }"
@mousedown.prevent="insertGenericPlaceholder('fallback', placeholder.name, true)"
@mouseenter="fallbackPromptPopup.selectedIndex = index"
>
<div class="placeholder-name">
<code v-html="`{{${placeholder.name}}}`"></code>
</div>
<div class="placeholder-desc">{{ placeholder.description }}</div>
</div>
<div class="placeholder-desc">{{ placeholder.description }}</div>
</div>
</div>
</div>
</Teleport>
</Teleport>
</div>
</div>
</div>
</template>
</div>
</div>
</div>
@@ -927,13 +955,11 @@ const emit = defineEmits<{
const currentSection = ref(props.initialSection || 'basic');
const saving = ref(false);
const allModels = ref<ModelConfig[]>([]);
const kbOptions = ref<{ label: string; value: string }[]>([]);
const kbOptions = ref<{ label: string; value: string; type?: 'document' | 'faq'; count?: number }[]>([]);
const mcpOptions = ref<{ label: string; value: string }[]>([]);
// 系统默认配置(用于内置智能体显示默认提示词)
const defaultSystemPrompt = ref(''); // 普通模式默认提示词
const defaultSystemPromptWebEnabled = ref(''); // Agent模式 Web开启时默认提示词
const defaultSystemPromptWebDisabled = ref(''); // Agent模式 Web关闭时默认提示词
const defaultSystemPrompt = ref(''); // 统一的默认系统提示词
const defaultContextTemplate = ref('');
const defaultRewritePromptSystem = ref('');
const defaultRewritePromptUser = ref('');
@@ -974,6 +1000,18 @@ const hasKnowledgeBase = computed(() => {
return kbSelectionMode.value !== 'none';
});
// 检测选择的知识库中是否包含 FAQ 类型
const hasFaqKnowledgeBase = computed(() => {
if (kbSelectionMode.value === 'none') return false;
if (kbSelectionMode.value === 'all') {
// 全部知识库模式,检查是否有任何 FAQ 类型的知识库
return kbOptions.value.some(kb => kb.type === 'faq');
}
// 指定知识库模式,检查选中的知识库中是否有 FAQ 类型
const selectedKbIds = formData.value.config.knowledge_bases || [];
return kbOptions.value.some(kb => selectedKbIds.includes(kb.value) && kb.type === 'faq');
});
const availableTools = computed(() => {
return allTools.map(tool => ({
...tool,
@@ -1076,10 +1114,6 @@ const navItems = computed(() => {
if (!isAgentMode.value) {
items.push({ key: 'conversation', icon: 'chat', label: t('agent.editor.conversationSettings') || '多轮对话' });
}
// 普通模式才显示高级设置
if (!isAgentMode.value) {
items.push({ key: 'advanced', icon: 'setting', label: t('agent.editor.advancedSettings') || '高级设置' });
}
return items;
});
@@ -1092,7 +1126,6 @@ const defaultFormData = {
// 基础设置
agent_mode: 'quick-answer' as 'quick-answer' | 'smart-reasoning',
system_prompt: '',
system_prompt_web_enabled: '',
context_template: '{{query}}',
// 模型设置
model_id: '',
@@ -1109,6 +1142,10 @@ const defaultFormData = {
// 知识库设置
kb_selection_mode: 'none' as 'all' | 'selected' | 'none',
knowledge_bases: [] as string[],
// FAQ 策略设置
faq_priority_enabled: true, // 是否启用 FAQ 优先策略
faq_direct_answer_threshold: 0.9, // FAQ 直接回答阈值(相似度高于此值直接使用 FAQ 答案)
faq_score_boost: 1.2, // FAQ 分数加权系数
// 网络搜索设置
web_search_enabled: false,
web_search_max_results: 5,
@@ -1153,24 +1190,11 @@ const systemPromptPlaceholder = computed(() => {
return t('agent.editor.systemPromptPlaceholder');
});
// 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(() => {
return t('agent.editor.contextTemplatePlaceholder');
});
// Agent模式系统提示词Tab
const activePromptTab = ref<'web-disabled' | 'web-enabled'>('web-disabled');
// 是否需要配置 ReRank 模型(有知识库能力时需要)
const needsRerankModel = computed(() => {
return hasKnowledgeBase.value;
@@ -1269,12 +1293,9 @@ const fillBuiltinAgentDefaults = () => {
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;
// Agent 模式:填入统一的默认提示词
if (!config.system_prompt && defaultSystemPrompt.value) {
config.system_prompt = defaultSystemPrompt.value;
}
} else {
// 普通模式:填入默认系统提示词和上下文模板
@@ -1405,7 +1426,12 @@ const loadDependencies = async () => {
// 加载知识库列表
const kbRes: any = await listKnowledgeBases();
if (kbRes.data) {
kbOptions.value = kbRes.data.map((kb: any) => ({ label: kb.name, value: kb.id }));
kbOptions.value = kbRes.data.map((kb: any) => ({
label: kb.name,
value: kb.id,
type: kb.type || 'document',
count: kb.type === 'faq' ? (kb.chunk_count || 0) : (kb.knowledge_count || 0)
}));
}
// 加载 MCP 服务列表(只加载启用的)
@@ -1430,18 +1456,16 @@ const loadDependencies = async () => {
console.warn('Failed to load placeholders', e);
}
// 加载 Agent 模式默认提示词
// 加载 Agent 模式默认提示词(统一提示词)
const agentConfig = await getAgentConfig();
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;
if (agentConfig.data?.system_prompt) {
defaultSystemPrompt.value = agentConfig.data.system_prompt;
}
// 加载系统默认配置(用于内置智能体显示默认提示词)
// 加载系统默认配置(用于普通模式)
const conversationConfig = await getConversationConfig();
if (conversationConfig.data?.prompt) {
if (conversationConfig.data?.prompt && !defaultSystemPrompt.value) {
// 如果 Agent 配置没有提供默认提示词,则使用普通模式的
defaultSystemPrompt.value = conversationConfig.data.prompt;
}
if (conversationConfig.data?.context_template) {
@@ -2214,11 +2238,7 @@ watch(() => props.visible, (val) => {
// 模板选择处理函数
const handleSystemPromptTemplateSelect = (template: string) => {
if (activePromptTab.value === 'web-enabled') {
formData.value.config.system_prompt_web_enabled = template;
} else {
formData.value.config.system_prompt = template;
}
formData.value.config.system_prompt = template;
};
const handleContextTemplateSelect = (template: string) => {
@@ -2241,6 +2261,12 @@ const handleFallbackPromptTemplateSelect = (template: string) => {
formData.value.config.fallback_prompt = template;
};
// 辅助函数:检查提示词是否包含指定占位符
const hasPlaceholder = (text: string | undefined, placeholder: string): boolean => {
if (!text) return false;
return text.includes(`{{${placeholder}}}`);
};
const handleSave = async () => {
// 验证必填项(内置智能体不验证名称和系统提示词)
if (!isBuiltinAgent.value) {
@@ -2265,6 +2291,58 @@ const handleSave = async () => {
}
}
// 校验占位符(普通模式 + 开启知识库)
if (!isAgentMode.value && hasKnowledgeBase.value) {
const contextTemplate = formData.value.config.context_template || '';
if (!hasPlaceholder(contextTemplate, 'contexts')) {
MessagePlugin.error(t('agent.editor.contextsMissing') || '开启知识库时,上下文模板必须包含 {{contexts}} 占位符');
currentSection.value = 'basic';
return;
}
if (!hasPlaceholder(contextTemplate, 'query')) {
MessagePlugin.error(t('agent.editor.queryMissingInContext') || '上下文模板必须包含 {{query}} 占位符');
currentSection.value = 'basic';
return;
}
}
// 校验占位符(Agent 模式 + 开启知识库)
if (isAgentMode.value && hasKnowledgeBase.value) {
const systemPrompt = formData.value.config.system_prompt || '';
if (!hasPlaceholder(systemPrompt, 'knowledge_bases')) {
MessagePlugin.warning(t('agent.editor.knowledgeBasesMissing') || '建议在系统提示词中包含 {{knowledge_bases}} 占位符,以便模型了解可用的知识库');
}
}
// 校验占位符(普通模式 + 开启多轮对话改写)
if (!isAgentMode.value && formData.value.config.multi_turn_enabled && formData.value.config.enable_rewrite) {
const rewritePrompt = formData.value.config.rewrite_prompt_user || '';
// 只有用户自定义了改写提示词时才校验
if (rewritePrompt.trim()) {
if (!hasPlaceholder(rewritePrompt, 'query')) {
MessagePlugin.error(t('agent.editor.queryMissingInRewrite') || '改写用户提示词必须包含 {{query}} 占位符');
currentSection.value = 'conversation';
return;
}
if (!hasPlaceholder(rewritePrompt, 'conversation')) {
MessagePlugin.error(t('agent.editor.conversationMissing') || '改写用户提示词必须包含 {{conversation}} 占位符');
currentSection.value = 'conversation';
return;
}
}
}
// 校验占位符(兜底策略为模型生成时)
if (!isAgentMode.value && formData.value.config.fallback_strategy === 'model') {
const fallbackPrompt = formData.value.config.fallback_prompt || '';
// 只有用户自定义了兜底提示词时才校验
if (fallbackPrompt.trim() && !hasPlaceholder(fallbackPrompt, 'query')) {
MessagePlugin.error(t('agent.editor.queryMissingInFallback') || '兜底提示词必须包含 {{query}} 占位符');
currentSection.value = 'retrieval';
return;
}
}
if (!formData.value.config.model_id) {
MessagePlugin.error(t('agent.editor.modelRequired'));
currentSection.value = 'model';
@@ -3008,4 +3086,85 @@ const handleSave = async () => {
}
}
}
// 知识库选项样式
.kb-option-item {
display: flex;
align-items: center;
gap: 6px;
}
.kb-option-icon {
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
font-size: 16px;
// Document KB - Greenish
&.doc-icon {
color: #10b981;
}
// FAQ KB - Blueish
&.faq-icon {
color: #0052d9;
}
}
.kb-option-label {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.kb-option-count {
flex-shrink: 0;
font-size: 12px;
color: #999;
}
// FAQ 策略区域样式
.faq-strategy-section {
margin-top: 24px;
padding: 16px;
background: rgba(0, 82, 217, 0.04);
border: 1px solid rgba(0, 82, 217, 0.15);
border-radius: 8px;
}
.faq-strategy-header {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 16px;
font-size: 14px;
font-weight: 600;
color: #0052d9;
.faq-icon {
font-size: 18px;
}
.help-icon {
font-size: 14px;
color: #999;
cursor: help;
}
}
.faq-strategy-section .setting-row {
padding: 12px 0;
border-bottom: 1px solid rgba(0, 82, 217, 0.1);
&:last-child {
border-bottom: none;
padding-bottom: 0;
}
&:first-of-type {
padding-top: 0;
}
}
</style>
+36 -96
View File
@@ -161,54 +161,27 @@
</t-button>
</div>
<p class="prompt-tab-hint">
{{ $t('agentSettings.systemPrompt.tabHint') }}(留空则使用系统默认)
{{ $t('agentSettings.systemPrompt.tabHint') }}(留空则使用系统默认,使用 {{web_search_status}} 占位符动态控制网络搜索行为)
</p>
<div class="system-prompt-tabs">
<t-tabs
v-model="activeSystemPromptTab"
class="system-prompt-variant-tabs"
>
<t-tab-panel value="web-enabled" :label="$t('agentSettings.systemPrompt.tabWebOn')">
<div v-if="activeSystemPromptTab === 'web-enabled'" class="prompt-textarea-wrapper textarea-with-template">
<t-textarea
ref="promptTextareaRef"
v-model="localSystemPromptWebEnabled"
:autosize="{ minRows: 15, maxRows: 30 }"
:placeholder="$t('agentSettings.systemPrompt.placeholder')"
@blur="handleSystemPromptChange('web-enabled', $event)"
@input="handlePromptInput"
@keydown="handlePromptKeydown"
style="width: 100%; font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; font-size: 13px;"
/>
<PromptTemplateSelector
type="systemPrompt"
position="corner"
:hasKnowledgeBase="true"
@select="handleAgentSystemPromptTemplateSelect"
/>
</div>
</t-tab-panel>
<t-tab-panel value="web-disabled" :label="$t('agentSettings.systemPrompt.tabWebOff')">
<div v-if="activeSystemPromptTab === 'web-disabled'" class="prompt-textarea-wrapper textarea-with-template">
<t-textarea
ref="promptTextareaRef"
v-model="localSystemPromptWebDisabled"
:autosize="{ minRows: 15, maxRows: 30 }"
:placeholder="$t('agentSettings.systemPrompt.placeholder')"
@blur="handleSystemPromptChange('web-disabled', $event)"
@input="handlePromptInput"
@keydown="handlePromptKeydown"
style="width: 100%; font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; font-size: 13px;"
/>
<PromptTemplateSelector
type="systemPrompt"
position="corner"
:hasKnowledgeBase="true"
@select="handleAgentSystemPromptTemplateSelect"
/>
</div>
</t-tab-panel>
</t-tabs>
<div class="prompt-textarea-wrapper textarea-with-template">
<t-textarea
ref="promptTextareaRef"
v-model="localSystemPrompt"
:autosize="{ minRows: 15, maxRows: 30 }"
:placeholder="$t('agentSettings.systemPrompt.placeholder')"
@blur="handleSystemPromptChange"
@input="handlePromptInput"
@keydown="handlePromptKeydown"
style="width: 100%; font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; font-size: 13px;"
/>
<PromptTemplateSelector
type="systemPrompt"
position="corner"
:hasKnowledgeBase="true"
@select="handleAgentSystemPromptTemplateSelect"
/>
</div>
</div>
<!-- 占位符提示下拉框 -->
<teleport to="body">
@@ -723,20 +696,9 @@ const localMaxIterations = ref(5)
const localTemperature = ref(0.7)
const localAllowedTools = ref<string[]>([])
type SystemPromptTab = 'web-enabled' | 'web-disabled'
const activeSystemPromptTab = ref<SystemPromptTab>('web-enabled')
const localSystemPromptWebEnabled = ref('')
const localSystemPromptWebDisabled = ref('')
const systemPromptRefs: Record<SystemPromptTab, Ref<string>> = {
'web-enabled': localSystemPromptWebEnabled,
'web-disabled': localSystemPromptWebDisabled,
}
const savedSystemPromptMap: Record<SystemPromptTab, string> = {
'web-enabled': '',
'web-disabled': '',
}
const getPromptRefByTab = (tab: SystemPromptTab) => systemPromptRefs[tab]
const getActivePromptRef = () => getPromptRefByTab(activeSystemPromptTab.value)
// 统一系统提示词
const localSystemPrompt = ref('')
let savedSystemPrompt = ''
// 普通模式本地状态
const localContextTemplate = ref('')
@@ -838,8 +800,7 @@ const buildAgentConfigPayload = (overrides: Partial<AgentConfig> = {}): AgentCon
reflection_enabled: false,
allowed_tools: localAllowedTools.value,
temperature: localTemperature.value,
system_prompt_web_enabled: localSystemPromptWebEnabled.value,
system_prompt_web_disabled: localSystemPromptWebDisabled.value,
system_prompt: localSystemPrompt.value,
...overrides,
})
@@ -929,12 +890,6 @@ let placeholderPopupTimer: any = null
const placeholderPrefix = ref('') // 当前输入的前缀,用于过滤
const popupStyle = ref({ top: '0px', left: '0px' }) // 提示框位置
watch(activeSystemPromptTab, () => {
showPlaceholderPopup.value = false
placeholderPrefix.value = ''
selectedPlaceholderIndex.value = 0
})
// 设置 textarea 原生事件监听器
const setupTextareaEventListeners = () => {
nextTick(() => {
@@ -1048,12 +1003,9 @@ onMounted(async () => {
lastSavedValue = config.max_iterations // 初始化时记录已保存的值
localTemperature.value = config.temperature
localAllowedTools.value = config.allowed_tools || []
const promptWebEnabled = config.system_prompt_web_enabled || ''
const promptWebDisabled = config.system_prompt_web_disabled || ''
localSystemPromptWebEnabled.value = promptWebEnabled
localSystemPromptWebDisabled.value = promptWebDisabled
savedSystemPromptMap['web-enabled'] = promptWebEnabled
savedSystemPromptMap['web-disabled'] = promptWebDisabled
const systemPrompt = config.system_prompt || ''
localSystemPrompt.value = systemPrompt
savedSystemPrompt = systemPrompt
availableTools.value = config.available_tools || []
availablePlaceholders.value = config.available_placeholders || []
@@ -1070,8 +1022,7 @@ onMounted(async () => {
maxIterations: config.max_iterations,
temperature: config.temperature,
allowedTools: config.allowed_tools || [],
system_prompt_web_enabled: promptWebEnabled,
system_prompt_web_disabled: promptWebDisabled,
system_prompt: systemPrompt,
})
// 加载普通模式配置
@@ -1432,25 +1383,21 @@ const handleResetToDefault = async () => {
try {
isResettingPrompt.value = true
// 通过设置 system_prompt_web_* 为空字符串来获取默认值
// 通过设置 system_prompt 为空字符串来获取默认值
// 后端在字段为空时会返回默认值
const tempConfig = buildAgentConfigPayload({
system_prompt_web_enabled: '',
system_prompt_web_disabled: '',
system_prompt: '',
})
await updateAgentConfig(tempConfig)
// 重新加载配置以获取默认 Prompt 的完整内容
const res = await getAgentConfig()
const defaultPromptWebEnabled = res.data.system_prompt_web_enabled || ''
const defaultPromptWebDisabled = res.data.system_prompt_web_disabled || ''
const defaultPrompt = res.data.system_prompt || ''
// 设置为默认 Prompt 的内容
localSystemPromptWebEnabled.value = defaultPromptWebEnabled
localSystemPromptWebDisabled.value = defaultPromptWebDisabled
savedSystemPromptMap['web-enabled'] = defaultPromptWebEnabled
savedSystemPromptMap['web-disabled'] = defaultPromptWebDisabled
localSystemPrompt.value = defaultPrompt
savedSystemPrompt = defaultPrompt
MessagePlugin.success(t('agentSettings.toasts.resetToDefault'))
confirmDialog.hide()
@@ -1465,7 +1412,7 @@ const handleResetToDefault = async () => {
}
// 处理系统 Prompt 变化
const handleSystemPromptChange = async (tab: SystemPromptTab, e?: FocusEvent) => {
const handleSystemPromptChange = async (e?: FocusEvent) => {
// 如果点击的是占位符提示框,不触发保存
if (e?.relatedTarget) {
const target = e.relatedTarget as HTMLElement
@@ -1487,19 +1434,16 @@ const handleSystemPromptChange = async (tab: SystemPromptTab, e?: FocusEvent) =>
// 如果正在初始化,不触发保存
if (isInitializing.value) return
const promptRef = getPromptRefByTab(tab)
const savedValue = savedSystemPromptMap[tab]
// 检查内容是否变化
if (promptRef.value === savedValue) {
if (localSystemPrompt.value === savedSystemPrompt) {
return // 内容没变,不调用接口
}
try {
const config = buildAgentConfigPayload()
await updateAgentConfig(config)
savedSystemPromptMap[tab] = promptRef.value // 更新已保存的值
savedSystemPrompt = localSystemPrompt.value // 更新已保存的值
MessagePlugin.success(t('agentSettings.toasts.systemPromptSaved'))
} catch (error) {
console.error('保存系统 Prompt 失败:', error)
@@ -1725,11 +1669,7 @@ const handleFallbackPromptChange = async () => {
// 模板选择处理函数
const handleAgentSystemPromptTemplateSelect = (template: string) => {
if (activeSystemPromptTab.value === 'web-enabled') {
localSystemPromptWebEnabled.value = template
} else {
localSystemPromptWebDisabled.value = template
}
localSystemPrompt.value = template
}
const handleNormalSystemPromptTemplateSelect = (template: string) => {