Merge branch 'custom_agent'

This commit is contained in:
wizardchen
2025-12-29 17:01:23 +08:00
64 changed files with 10364 additions and 1965 deletions
File diff suppressed because it is too large Load Diff
+894
View File
@@ -0,0 +1,894 @@
<template>
<div class="agent-list-container">
<!-- 头部 -->
<div class="header">
<div class="header-title">
<h2>{{ $t('agent.title') }}</h2>
<p class="header-subtitle">{{ $t('agent.subtitle') }}</p>
</div>
</div>
<div class="header-divider"></div>
<!-- 卡片网格 -->
<div v-if="agents.length > 0" class="agent-card-wrap">
<div
v-for="agent in agents"
:key="agent.id"
class="agent-card"
:class="{
'is-builtin': agent.is_builtin,
'agent-mode-normal': agent.config?.agent_mode === 'quick-answer',
'agent-mode-agent': agent.config?.agent_mode === 'smart-reasoning'
}"
@click="handleCardClick(agent)"
>
<!-- 装饰星星 -->
<div class="card-decoration">
<svg class="star-icon" width="24" height="24" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M10 3L10.8 6.2C10.9 6.7 11.3 7.1 11.8 7.2L15 8L11.8 8.8C11.3 8.9 10.9 9.3 10.8 9.8L10 13L9.2 9.8C9.1 9.3 8.7 8.9 8.2 8.8L5 8L8.2 7.2C8.7 7.1 9.1 6.7 9.2 6.2L10 3Z" stroke="currentColor" stroke-width="0.8" stroke-linecap="round" stroke-linejoin="round" fill="currentColor" fill-opacity="0.15"/>
</svg>
<svg class="star-icon small" width="14" height="14" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M10 3L10.8 6.2C10.9 6.7 11.3 7.1 11.8 7.2L15 8L11.8 8.8C11.3 8.9 10.9 9.3 10.8 9.8L10 13L9.2 9.8C9.1 9.3 8.7 8.9 8.2 8.8L5 8L8.2 7.2C8.7 7.1 9.1 6.7 9.2 6.2L10 3Z" stroke="currentColor" stroke-width="0.8" stroke-linecap="round" stroke-linejoin="round" fill="currentColor" fill-opacity="0.15"/>
</svg>
</div>
<!-- 卡片头部 -->
<div class="card-header">
<div class="card-header-left">
<!-- 内置智能体使用简洁图标 -->
<div v-if="agent.is_builtin" class="builtin-avatar" :class="agent.config?.agent_mode === 'smart-reasoning' ? 'agent' : 'normal'">
<t-icon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'" size="18px" />
</div>
<!-- 自定义智能体使用 AgentAvatar -->
<AgentAvatar v-else :name="agent.name" size="medium" />
<span class="card-title" :title="agent.name">{{ agent.name }}</span>
</div>
<t-popup
v-model="agent.showMore"
overlayClassName="card-more-popup"
:on-visible-change="(visible: boolean) => onVisibleChange(visible, agent)"
trigger="click"
destroy-on-close
placement="bottom-right"
>
<div
class="more-wrap"
@click.stop
:class="{ 'active-more': agent.showMore }"
>
<img class="more-icon" src="@/assets/img/more.png" alt="" />
</div>
<template #content>
<div class="popup-menu">
<div class="popup-menu-item" @click="handleEdit(agent)">
<t-icon class="menu-icon" name="edit" />
<span>{{ $t('common.edit') }}</span>
</div>
<div class="popup-menu-item" @click="handleCopy(agent)">
<t-icon class="menu-icon" name="file-copy" />
<span>{{ $t('common.copy') }}</span>
</div>
<div v-if="!agent.is_builtin" class="popup-menu-item delete" @click="handleDelete(agent)">
<t-icon class="menu-icon" name="delete" />
<span>{{ $t('common.delete') }}</span>
</div>
</div>
</template>
</t-popup>
</div>
<!-- 卡片内容 -->
<div class="card-content">
<div class="card-description">
{{ agent.description || $t('agent.noDescription') }}
</div>
</div>
<!-- 卡片底部 -->
<div class="card-bottom">
<div class="bottom-left">
<div class="feature-badges">
<t-tooltip :content="agent.config?.agent_mode === 'smart-reasoning' ? $t('agent.mode.agent') : $t('agent.mode.normal')" placement="top">
<div class="feature-badge" :class="{ 'mode-normal': agent.config?.agent_mode === 'quick-answer', 'mode-agent': agent.config?.agent_mode === 'smart-reasoning' }">
<t-icon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'" size="14px" />
</div>
</t-tooltip>
<t-tooltip v-if="agent.config?.web_search_enabled" :content="$t('agent.features.webSearch')" placement="top">
<div class="feature-badge web-search">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="8" cy="8" r="6" stroke="currentColor" stroke-width="1.2" fill="none"/>
<ellipse cx="8" cy="8" rx="2.5" ry="6" stroke="currentColor" stroke-width="1.2" fill="none"/>
<line x1="2" y1="6" x2="14" y2="6" stroke="currentColor" stroke-width="1.2"/>
<line x1="2" y1="10" x2="14" y2="10" stroke="currentColor" stroke-width="1.2"/>
</svg>
</div>
</t-tooltip>
<t-tooltip v-if="agent.config?.knowledge_bases?.length || agent.config?.kb_selection_mode === 'all'" :content="$t('agent.features.knowledgeBase')" placement="top">
<div class="feature-badge knowledge">
<t-icon name="folder" size="16px" />
</div>
</t-tooltip>
<t-tooltip v-if="agent.config?.mcp_services?.length || agent.config?.mcp_selection_mode === 'all'" :content="$t('agent.features.mcp')" placement="top">
<div class="feature-badge mcp">
<t-icon name="extension" size="16px" />
</div>
</t-tooltip>
<t-tooltip v-if="agent.config?.multi_turn_enabled" :content="$t('agent.features.multiTurn')" placement="top">
<div class="feature-badge multi-turn">
<t-icon name="chat-bubble" size="16px" />
</div>
</t-tooltip>
</div>
</div>
<div v-if="agent.is_builtin" class="builtin-badge">
<t-icon name="lock-on" size="12px" />
<span>{{ $t('agent.builtin') }}</span>
</div>
<span v-else-if="agent.updated_at" class="card-time">{{ formatDate(agent.updated_at) }}</span>
</div>
</div>
</div>
<!-- 空状态 -->
<div v-else-if="!loading" class="empty-state">
<img class="empty-img" src="@/assets/img/upload.svg" alt="">
<span class="empty-txt">{{ $t('agent.empty.title') }}</span>
<span class="empty-desc">{{ $t('agent.empty.description') }}</span>
</div>
<!-- 删除确认对话框 -->
<t-dialog
v-model:visible="deleteVisible"
dialogClassName="del-agent-dialog"
:closeBtn="false"
:cancelBtn="null"
:confirmBtn="null"
>
<div class="circle-wrap">
<div class="dialog-header">
<img class="circle-img" src="@/assets/img/circle.png" alt="">
<span class="circle-title">{{ $t('agent.delete.confirmTitle') }}</span>
</div>
<span class="del-circle-txt">
{{ $t('agent.delete.confirmMessage', { name: deletingAgent?.name ?? '' }) }}
</span>
<div class="circle-btn">
<span class="circle-btn-txt" @click="deleteVisible = false">{{ $t('common.cancel') }}</span>
<span class="circle-btn-txt confirm" @click="confirmDelete">{{ $t('agent.delete.confirmButton') }}</span>
</div>
</div>
</t-dialog>
<!-- 智能体编辑器弹窗 -->
<AgentEditorModal
:visible="editorVisible"
:mode="editorMode"
:agent="editingAgent"
:initialSection="editorInitialSection"
@update:visible="editorVisible = $event"
@success="handleEditorSuccess"
/>
</div>
</template>
<script setup lang="ts">
import { onMounted, onUnmounted, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { MessagePlugin, Icon as TIcon } from 'tdesign-vue-next'
import { listAgents, deleteAgent, copyAgent, type CustomAgent } from '@/api/agent'
import { formatStringDate } from '@/utils/index'
import { useI18n } from 'vue-i18n'
import AgentEditorModal from './AgentEditorModal.vue'
import AgentAvatar from '@/components/AgentAvatar.vue'
const { t } = useI18n()
const route = useRoute()
const router = useRouter()
interface AgentWithUI extends CustomAgent {
showMore?: boolean
}
const agents = ref<AgentWithUI[]>([])
const loading = ref(false)
const deleteVisible = ref(false)
const deletingAgent = ref<AgentWithUI | null>(null)
const editorVisible = ref(false)
const editorMode = ref<'create' | 'edit'>('create')
const editingAgent = ref<CustomAgent | null>(null)
const editorInitialSection = ref<string>('basic')
const fetchList = () => {
loading.value = true
return listAgents().then((res: any) => {
const data = res.data || []
// 显示所有智能体(包括内置智能体)
agents.value = data.map((agent: CustomAgent) => ({
...agent,
showMore: false
}))
// 检查 URL 中是否有 edit 参数,如果有则打开对应智能体的编辑模态框
checkAndOpenEditModal()
}).finally(() => loading.value = false)
}
// 检查 URL 参数并打开编辑模态框
const checkAndOpenEditModal = () => {
const editId = route.query.edit as string
const section = route.query.section as string
if (editId) {
const agent = agents.value.find(a => a.id === editId)
if (agent) {
editingAgent.value = agent
editorMode.value = 'edit'
editorInitialSection.value = section || 'basic'
editorVisible.value = true
}
// 清除 URL 中的参数
router.replace({ path: route.path, query: {} })
}
}
// 监听菜单创建智能体事件
const handleOpenAgentEditor = (event: CustomEvent) => {
if (event.detail?.mode === 'create') {
openCreateModal()
}
}
onMounted(() => {
fetchList()
window.addEventListener('openAgentEditor', handleOpenAgentEditor as EventListener)
})
onUnmounted(() => {
window.removeEventListener('openAgentEditor', handleOpenAgentEditor as EventListener)
})
const onVisibleChange = (visible: boolean, agent: AgentWithUI) => {
if (!visible) {
agent.showMore = false
}
}
const handleCardClick = (agent: AgentWithUI) => {
// 如果弹窗正在显示,不触发编辑
if (agent.showMore) {
return
}
// 点击卡片编辑(包括内置智能体)
handleEdit(agent)
}
const handleEdit = (agent: AgentWithUI) => {
agent.showMore = false
editingAgent.value = agent
editorMode.value = 'edit'
editorVisible.value = true
}
const handleDelete = (agent: AgentWithUI) => {
agent.showMore = false
deletingAgent.value = agent
deleteVisible.value = true
}
const handleCopy = (agent: AgentWithUI) => {
agent.showMore = false
copyAgent(agent.id).then((res: any) => {
if (res.data) {
MessagePlugin.success(t('agent.messages.copied'))
fetchList()
} else {
MessagePlugin.error(res.message || t('agent.messages.copyFailed'))
}
}).catch((e: any) => {
MessagePlugin.error(e?.message || t('agent.messages.copyFailed'))
})
}
const confirmDelete = () => {
if (!deletingAgent.value) return
deleteAgent(deletingAgent.value.id).then((res: any) => {
if (res.success) {
MessagePlugin.success(t('agent.messages.deleted'))
deleteVisible.value = false
deletingAgent.value = null
fetchList()
} else {
MessagePlugin.error(res.message || t('agent.messages.deleteFailed'))
}
}).catch((e: any) => {
MessagePlugin.error(e?.message || t('agent.messages.deleteFailed'))
})
}
const handleEditorSuccess = () => {
editorVisible.value = false
editingAgent.value = null
fetchList()
}
const formatDate = (dateStr: string) => {
if (!dateStr) return ''
return formatStringDate(new Date(dateStr))
}
// 暴露创建方法供外部调用
const openCreateModal = () => {
editingAgent.value = null
editorMode.value = 'create'
editorVisible.value = true
}
defineExpose({
openCreateModal
})
</script>
<style scoped lang="less">
.agent-list-container {
padding: 24px 44px;
margin: 0 20px;
height: calc(100vh);
overflow-y: auto;
box-sizing: border-box;
flex: 1;
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
.header-title {
display: flex;
flex-direction: column;
gap: 4px;
}
h2 {
margin: 0;
color: #000000e6;
font-family: "PingFang SC";
font-size: 24px;
font-weight: 600;
line-height: 32px;
}
}
.header-subtitle {
margin: 0;
color: #00000099;
font-family: "PingFang SC";
font-size: 14px;
font-weight: 400;
line-height: 20px;
}
.header-divider {
height: 1px;
background: #e7ebf0;
margin-bottom: 20px;
}
.agent-card-wrap {
display: grid;
gap: 16px;
grid-template-columns: 1fr;
}
.agent-card {
border: 1px solid #f0f0f0;
border-radius: 12px;
overflow: hidden;
box-sizing: border-box;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
background: #fff;
position: relative;
cursor: pointer;
transition: all 0.25s ease;
padding: 16px 18px;
display: flex;
flex-direction: column;
height: 160px;
&:hover {
border-color: #07c05f;
box-shadow: 0 4px 12px rgba(7, 192, 95, 0.12);
}
// 普通模式样式
&.agent-mode-normal {
background: linear-gradient(135deg, #ffffff 0%, #f8fcfa 100%);
border-color: #e8f5ed;
&:hover {
border-color: #07c05f;
background: linear-gradient(135deg, #ffffff 0%, #f0fdf4 100%);
}
.card-decoration {
color: rgba(7, 192, 95, 0.35);
}
&:hover .card-decoration {
color: rgba(7, 192, 95, 0.5);
}
}
// Agent 模式样式
&.agent-mode-agent {
background: linear-gradient(135deg, #ffffff 0%, #f8f5ff 100%);
border-color: #ede8ff;
&:hover {
border-color: #7c4dff;
box-shadow: 0 4px 12px rgba(124, 77, 255, 0.12);
background: linear-gradient(135deg, #ffffff 0%, #f3efff 100%);
}
.card-decoration {
color: rgba(124, 77, 255, 0.35);
}
&:hover .card-decoration {
color: rgba(124, 77, 255, 0.5);
}
}
// 确保内容在装饰之上
.card-header,
.card-content,
.card-bottom {
position: relative;
z-index: 1;
}
}
.card-decoration {
position: absolute;
top: 12px;
right: 50px;
display: flex;
align-items: flex-start;
gap: 4px;
pointer-events: none;
z-index: 0;
transition: color 0.25s ease;
.star-icon {
opacity: 0.9;
&.small {
margin-top: 14px;
opacity: 0.7;
}
}
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.card-header-left {
display: flex;
align-items: center;
gap: 10px;
flex: 1;
min-width: 0;
}
.card-title {
color: #1a1a1a;
font-family: "PingFang SC";
font-size: 15px;
font-weight: 600;
line-height: 22px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
flex: 1;
min-width: 0;
}
.builtin-badge {
display: inline-flex;
align-items: center;
gap: 3px;
padding: 2px 8px;
border-radius: 10px;
background: rgba(0, 0, 0, 0.04);
color: #666;
font-family: "PingFang SC";
font-size: 11px;
font-weight: 500;
flex-shrink: 0;
}
.builtin-avatar {
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
border-radius: 8px;
flex-shrink: 0;
&.normal {
background: linear-gradient(135deg, rgba(7, 192, 95, 0.15) 0%, rgba(7, 192, 95, 0.08) 100%);
color: #059669;
}
&.agent {
background: linear-gradient(135deg, rgba(124, 77, 255, 0.15) 0%, rgba(124, 77, 255, 0.08) 100%);
color: #7c4dff;
}
}
.edit-btn {
display: flex;
width: 32px;
height: 32px;
justify-content: center;
align-items: center;
border-radius: 6px;
cursor: pointer;
flex-shrink: 0;
transition: all 0.2s ease;
color: #00000066;
&:hover {
background: rgba(0, 0, 0, 0.06);
color: #07c05f;
}
}
.more-wrap {
display: flex;
width: 28px;
height: 28px;
justify-content: center;
align-items: center;
border-radius: 6px;
cursor: pointer;
flex-shrink: 0;
transition: all 0.2s ease;
opacity: 0;
.agent-card:hover & {
opacity: 0.6;
}
&:hover {
background: rgba(0, 0, 0, 0.05);
opacity: 1 !important;
}
&.active-more {
background: rgba(0, 0, 0, 0.06);
opacity: 1 !important;
}
.more-icon {
width: 16px;
height: 16px;
}
}
.card-content {
flex: 1;
margin-bottom: 12px;
overflow: hidden;
}
.card-description {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
line-clamp: 2;
overflow: hidden;
color: #666;
font-family: "PingFang SC";
font-size: 13px;
font-weight: 400;
line-height: 20px;
}
.card-bottom {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: auto;
padding-top: 12px;
border-top: 1px solid #f0f0f0;
}
.bottom-left {
display: flex;
align-items: center;
gap: 8px;
}
.feature-badges {
display: flex;
align-items: center;
gap: 4px;
}
.feature-badge {
display: flex;
align-items: center;
justify-content: center;
width: 26px;
height: 26px;
border-radius: 6px;
cursor: default;
transition: background 0.2s ease;
&.mode-normal {
background: rgba(7, 192, 95, 0.08);
color: #059669;
&:hover {
background: rgba(7, 192, 95, 0.12);
}
}
&.mode-agent {
background: rgba(124, 77, 255, 0.08);
color: #7c4dff;
&:hover {
background: rgba(124, 77, 255, 0.12);
}
}
&.web-search {
background: rgba(255, 152, 0, 0.08);
color: #f59e0b;
&:hover {
background: rgba(255, 152, 0, 0.12);
}
}
&.knowledge {
background: rgba(7, 192, 95, 0.08);
color: #059669;
&:hover {
background: rgba(7, 192, 95, 0.12);
}
}
&.mcp {
background: rgba(236, 72, 153, 0.08);
color: #ec4899;
&:hover {
background: rgba(236, 72, 153, 0.12);
}
}
&.multi-turn {
background: rgba(59, 130, 246, 0.08);
color: #3b82f6;
&:hover {
background: rgba(59, 130, 246, 0.12);
}
}
}
.card-time {
color: #999;
font-family: "PingFang SC";
font-size: 12px;
font-weight: 400;
}
.empty-state {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 60px 20px;
.empty-img {
width: 162px;
height: 162px;
margin-bottom: 20px;
}
.empty-txt {
color: #00000099;
font-family: "PingFang SC";
font-size: 16px;
font-weight: 600;
line-height: 26px;
margin-bottom: 8px;
}
.empty-desc {
color: #00000066;
font-family: "PingFang SC";
font-size: 14px;
font-weight: 400;
line-height: 22px;
}
}
// 响应式布局
@media (min-width: 900px) {
.agent-card-wrap {
grid-template-columns: repeat(2, 1fr);
}
}
@media (min-width: 1250px) {
.agent-card-wrap {
grid-template-columns: repeat(3, 1fr);
}
}
@media (min-width: 1600px) {
.agent-card-wrap {
grid-template-columns: repeat(4, 1fr);
}
}
// 删除确认对话框样式
:deep(.del-agent-dialog) {
padding: 0px !important;
border-radius: 6px !important;
.t-dialog__header {
display: none;
}
.t-dialog__body {
padding: 16px;
}
.t-dialog__footer {
padding: 0;
}
}
:deep(.t-dialog__position.t-dialog--top) {
padding-top: 40vh !important;
}
.circle-wrap {
.dialog-header {
display: flex;
align-items: center;
margin-bottom: 8px;
}
.circle-img {
width: 20px;
height: 20px;
margin-right: 8px;
}
.circle-title {
color: #000000e6;
font-family: "PingFang SC";
font-size: 16px;
font-weight: 600;
line-height: 24px;
}
.del-circle-txt {
color: #00000099;
font-family: "PingFang SC";
font-size: 14px;
font-weight: 400;
line-height: 22px;
display: inline-block;
margin-left: 29px;
margin-bottom: 21px;
}
.circle-btn {
height: 22px;
width: 100%;
display: flex;
justify-content: flex-end;
}
.circle-btn-txt {
color: #000000e6;
font-family: "PingFang SC";
font-size: 14px;
font-weight: 400;
line-height: 22px;
cursor: pointer;
&:hover {
opacity: 0.8;
}
}
.confirm {
color: #FA5151;
margin-left: 40px;
&:hover {
opacity: 0.8;
}
}
}
</style>
<style lang="less">
// 更多操作弹窗样式
.card-more-popup {
z-index: 99 !important;
.t-popup__content {
padding: 6px 0 !important;
margin-top: 6px !important;
min-width: 140px;
border-radius: 6px !important;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1) !important;
border: 1px solid #e7ebf0 !important;
}
}
.popup-menu {
display: flex;
flex-direction: column;
}
.popup-menu-item {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 16px;
cursor: pointer;
transition: all 0.2s ease;
color: #000000e6;
font-family: "PingFang SC";
font-size: 14px;
font-weight: 400;
line-height: 20px;
.menu-icon {
font-size: 16px;
flex-shrink: 0;
color: #00000099;
transition: color 0.2s ease;
}
&:hover {
background: #f7f9fc;
.menu-icon {
color: #000000e6;
}
}
&.delete {
color: #000000e6;
&:hover {
background: #fff1f0;
color: #fa5151;
.menu-icon {
color: #fa5151;
}
}
}
}
</style>
+3
View File
@@ -314,6 +314,8 @@ const sendMsg = async (value, modelId = '', mentionedItems = []) => {
const kbIds = useSettingsStoreInstance.settings.selectedKnowledgeBases || [];
const knowledgeIds = useSettingsStoreInstance.settings.selectedFiles || [];
// Get selected agent ID
const selectedAgentId = useSettingsStoreInstance.selectedAgentId || '';
// Use agent-chat endpoint when agent is enabled, otherwise use knowledge-chat
@@ -327,6 +329,7 @@ const sendMsg = async (value, modelId = '', mentionedItems = []) => {
knowledge_base_ids: kbIds,
knowledge_ids: knowledgeIds,
agent_enabled: agentEnabled,
agent_id: selectedAgentId, // 传递选中的智能体 ID
web_search_enabled: webSearchEnabled,
summary_model_id: modelId,
mcp_service_ids: mcpServiceIds,
+101 -102
View File
@@ -116,23 +116,14 @@
<!-- 卡片底部 -->
<div class="card-bottom">
<div class="bottom-left">
<div class="type-badge" :class="{ 'document': (kb.type || 'document') === 'document', 'faq': kb.type === 'faq' }">
<t-icon :name="kb.type === 'faq' ? 'chat-bubble-help' : 'folder'" size="14px" />
<span>
{{ kb.type === 'faq' ? $t('knowledgeEditor.basic.typeFAQ') : $t('knowledgeEditor.basic.typeDocument') }}
({{ kb.type === 'faq' ? (kb.chunk_count || 0) : (kb.knowledge_count || 0) }})
</span>
<t-tooltip
v-if="kb.isProcessing"
:content="kb.type === 'document' && (kb.processing_count || 0) > 0
? $t('knowledgeList.processingDocuments', { count: kb.processing_count || 0 })
: $t('knowledgeList.processing')"
placement="top"
>
<t-icon name="loading" size="14px" class="processing-icon" />
</t-tooltip>
</div>
<div class="feature-badges">
<t-tooltip :content="kb.type === 'faq' ? $t('knowledgeEditor.basic.typeFAQ') : $t('knowledgeEditor.basic.typeDocument')" placement="top">
<div class="feature-badge" :class="{ 'type-document': (kb.type || 'document') === 'document', 'type-faq': kb.type === 'faq' }">
<t-icon :name="kb.type === 'faq' ? 'chat-bubble-help' : 'folder'" size="14px" />
<span class="badge-count">{{ kb.type === 'faq' ? (kb.chunk_count || 0) : (kb.knowledge_count || 0) }}</span>
<t-icon v-if="kb.isProcessing" name="loading" size="12px" class="processing-icon" />
</div>
</t-tooltip>
<t-tooltip v-if="kb.extract_config?.enabled" :content="$t('knowledgeList.features.knowledgeGraph')" placement="top">
<div class="feature-badge kg">
<t-icon name="relation" size="14px" />
@@ -700,27 +691,28 @@ const handleUploadFinishedEvent = (event: Event) => {
.kb-card-wrap {
display: grid;
gap: 20px;
gap: 16px;
grid-template-columns: 1fr;
}
.kb-card {
border: 2px solid #fbfbfb;
border-radius: 6px;
border: 1px solid #f0f0f0;
border-radius: 12px;
overflow: hidden;
box-sizing: border-box;
box-shadow: 0 0 8px 0 #00000005;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
background: #fff;
position: relative;
cursor: pointer;
transition: all 0.2s ease;
padding: 12px 16px 14px;
transition: all 0.25s ease;
padding: 16px 18px;
display: flex;
flex-direction: column;
min-height: 150px;
height: 160px;
&:hover {
border-color: #07c05f;
box-shadow: 0 4px 12px rgba(7, 192, 95, 0.12);
}
&.uninitialized {
@@ -731,12 +723,12 @@ const handleUploadFinishedEvent = (event: Event) => {
&.kb-type-document {
background: linear-gradient(135deg, #ffffff 0%, #f8fcfa 100%);
border-color: #e8f5ed;
&:hover {
border-color: #07c05f;
background: linear-gradient(135deg, #ffffff 0%, #f0fdf4 100%);
}
// 右上角装饰
&::after {
content: '';
@@ -746,7 +738,7 @@ const handleUploadFinishedEvent = (event: Event) => {
width: 60px;
height: 60px;
background: linear-gradient(135deg, rgba(7, 192, 95, 0.08) 0%, transparent 100%);
border-radius: 0 6px 0 100%;
border-radius: 0 12px 0 100%;
pointer-events: none;
z-index: 0;
}
@@ -756,12 +748,13 @@ const handleUploadFinishedEvent = (event: Event) => {
&.kb-type-faq {
background: linear-gradient(135deg, #ffffff 0%, #f8fbff 100%);
border-color: #e6f0ff;
&:hover {
border-color: #0052d9;
box-shadow: 0 4px 12px rgba(0, 82, 217, 0.12);
background: linear-gradient(135deg, #ffffff 0%, #eff6ff 100%);
}
// 右上角装饰
&::after {
content: '';
@@ -771,7 +764,7 @@ const handleUploadFinishedEvent = (event: Event) => {
width: 60px;
height: 60px;
background: linear-gradient(135deg, rgba(0, 82, 217, 0.08) 0%, transparent 100%);
border-radius: 0 6px 0 100%;
border-radius: 0 12px 0 100%;
pointer-events: none;
z-index: 0;
}
@@ -790,42 +783,46 @@ const handleUploadFinishedEvent = (event: Event) => {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
margin-bottom: 10px;
}
.card-title {
color: #000000e6;
color: #1a1a1a;
font-family: "PingFang SC";
font-size: 14px;
font-size: 15px;
font-weight: 600;
line-height: 22px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
flex: 1;
margin-right: 8px;
min-width: 0;
}
.more-wrap {
display: flex;
width: 32px;
height: 32px;
width: 28px;
height: 28px;
justify-content: center;
align-items: center;
border-radius: 6px;
cursor: pointer;
flex-shrink: 0;
transition: all 0.2s ease;
opacity: 0.7;
opacity: 0;
.kb-card:hover & {
opacity: 0.6;
}
&:hover {
background: rgba(0, 0, 0, 0.06);
opacity: 1;
background: rgba(0, 0, 0, 0.05);
opacity: 1 !important;
}
&.active-more {
background: rgba(0, 0, 0, 0.08);
opacity: 1;
background: rgba(0, 0, 0, 0.06);
opacity: 1 !important;
}
.more-icon {
@@ -836,7 +833,8 @@ const handleUploadFinishedEvent = (event: Event) => {
.card-content {
flex: 1;
margin-bottom: 10px;
margin-bottom: 12px;
overflow: hidden;
}
.card-description {
@@ -845,21 +843,20 @@ const handleUploadFinishedEvent = (event: Event) => {
-webkit-line-clamp: 2;
line-clamp: 2;
overflow: hidden;
color: #00000066;
color: #666;
font-family: "PingFang SC";
font-size: 12px;
font-size: 13px;
font-weight: 400;
line-height: 20px;
min-height: 40px;
}
.card-bottom {
display: flex;
align-items: center;
justify-content: space-between;
padding: 8px 0 0;
border-top: 1px solid #f0f0f0;
margin-top: auto;
padding-top: 12px;
border-top: 1px solid #f0f0f0;
}
.bottom-left {
@@ -868,88 +865,90 @@ const handleUploadFinishedEvent = (event: Event) => {
gap: 8px;
}
.type-badge {
display: inline-flex;
align-items: center;
gap: 4px;
padding: 3px 10px;
border-radius: 4px;
font-family: "PingFang SC";
font-size: 12px;
font-weight: 500;
line-height: 18px;
&.document {
background: rgba(7, 192, 95, 0.1);
color: #059669;
border: 1px solid rgba(7, 192, 95, 0.2);
}
&.faq {
background: rgba(0, 82, 217, 0.1);
color: #0052d9;
border: 1px solid rgba(0, 82, 217, 0.2);
}
.processing-icon {
animation: spin 1s linear infinite;
margin-left: 4px;
}
&.document .processing-icon {
color: #059669;
}
&.faq .processing-icon {
color: #0052d9;
}
}
.feature-badges {
display: flex;
align-items: center;
gap: 6px;
gap: 4px;
}
.feature-badge {
display: flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
border-radius: 4px;
cursor: pointer;
width: 26px;
height: 26px;
border-radius: 6px;
cursor: default;
transition: background 0.2s ease;
&.kg {
background: rgba(124, 77, 255, 0.1);
color: #7c4dff;
border: 1px solid rgba(124, 77, 255, 0.2);
&.type-document {
background: rgba(7, 192, 95, 0.08);
color: #059669;
width: auto;
padding: 0 8px;
gap: 4px;
&:hover {
background: rgba(124, 77, 255, 0.15);
background: rgba(7, 192, 95, 0.12);
}
.badge-count {
font-size: 12px;
font-weight: 500;
}
.processing-icon {
animation: spin 1s linear infinite;
}
}
&.type-faq {
background: rgba(0, 82, 217, 0.08);
color: #0052d9;
width: auto;
padding: 0 8px;
gap: 4px;
&:hover {
background: rgba(0, 82, 217, 0.12);
}
.badge-count {
font-size: 12px;
font-weight: 500;
}
.processing-icon {
animation: spin 1s linear infinite;
}
}
&.kg {
background: rgba(124, 77, 255, 0.08);
color: #7c4dff;
&:hover {
background: rgba(124, 77, 255, 0.12);
}
}
&.multimodal {
background: rgba(255, 152, 0, 0.1);
color: #ff9800;
border: 1px solid rgba(255, 152, 0, 0.2);
background: rgba(255, 152, 0, 0.08);
color: #f59e0b;
&:hover {
background: rgba(255, 152, 0, 0.15);
background: rgba(255, 152, 0, 0.12);
}
}
&.question {
background: rgba(0, 150, 136, 0.1);
background: rgba(0, 150, 136, 0.08);
color: #009688;
border: 1px solid rgba(0, 150, 136, 0.2);
&:hover {
background: rgba(0, 150, 136, 0.15);
background: rgba(0, 150, 136, 0.12);
}
}
}
@keyframes spin {
@@ -986,7 +985,7 @@ const handleUploadFinishedEvent = (event: Event) => {
}
.card-time {
color: #00000066;
color: #999;
font-family: "PingFang SC";
font-size: 12px;
font-weight: 400;
+174 -255
View File
@@ -4,6 +4,10 @@
<div class="section-header">
<h2>{{ $t('settings.conversationStrategy') }}</h2>
<p class="section-description">{{ $t('conversationSettings.description') }}</p>
<div class="global-config-notice">
<t-icon name="info-circle" />
<span>这些是全局默认配置,新建智能体时会继承这些设置。您也可以在智能体列表中单独配置每个智能体。</span>
</div>
</div>
<t-tabs v-model="activeTab" class="conversation-tabs">
@@ -146,17 +150,7 @@
</div>
<div class="setting-control full-width" style="position: relative;">
<div class="prompt-header">
<div class="prompt-toggle">
<span class="prompt-toggle-label">{{ $t('agentSettings.systemPrompt.custom') }}</span>
<t-switch
v-model="localUseCustomSystemPrompt"
:label="[$t('common.off'), $t('common.on')]"
size="large"
@change="handleUseCustomPromptToggle"
/>
</div>
<t-button
v-if="localUseCustomSystemPrompt"
theme="default"
variant="outline"
size="small"
@@ -167,54 +161,32 @@
</t-button>
</div>
<p class="prompt-tab-hint">
{{ $t('agentSettings.systemPrompt.tabHint') }}
{{ $t('agentSettings.systemPrompt.tabHint') }}(留空则使用系统默认,使用 {{web_search_status}} 占位符动态控制网络搜索行为)
</p>
<p v-if="!localUseCustomSystemPrompt" class="prompt-disabled-hint">
{{ $t('agentSettings.systemPrompt.disabledHint') }}
</p>
<div v-if="localUseCustomSystemPrompt" 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">
<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"
:readonly="!localUseCustomSystemPrompt"
:class="{ 'prompt-textarea-readonly': !localUseCustomSystemPrompt }"
style="width: 100%; font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; font-size: 13px;"
/>
</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">
<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"
:readonly="!localUseCustomSystemPrompt"
:class="{ 'prompt-textarea-readonly': !localUseCustomSystemPrompt }"
style="width: 100%; font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; font-size: 13px;"
/>
</div>
</t-tab-panel>
</t-tabs>
<div class="system-prompt-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">
<div
v-if="localUseCustomSystemPrompt && showPlaceholderPopup && filteredPlaceholders.length > 0"
v-if="showPlaceholderPopup && filteredPlaceholders.length > 0"
class="placeholder-popup-wrapper"
:style="popupStyle"
>
@@ -249,24 +221,10 @@
<div class="setting-row vertical">
<div class="setting-info">
<label>{{ $t('conversationSettings.systemPrompt.label') }}</label>
<p class="desc">{{ $t('conversationSettings.systemPrompt.desc') }}</p>
<p class="desc">{{ $t('conversationSettings.systemPrompt.desc') }}(留空则使用系统默认)</p>
</div>
<div class="setting-control full-width">
<div class="prompt-header">
<div class="prompt-toggle">
<span class="prompt-toggle-label">{{ $t('conversationSettings.systemPrompt.custom') }}</span>
<t-switch
v-model="localUseCustomSystemPromptNormal"
:label="[$t('common.off'), $t('common.on')]"
size="large"
@change="handleUseCustomSystemPromptNormalToggle"
/>
</div>
</div>
<p v-if="!localUseCustomSystemPromptNormal" class="prompt-disabled-hint">
{{ $t('conversationSettings.systemPrompt.disabledHint') }}
</p>
<div v-if="localUseCustomSystemPromptNormal" class="prompt-textarea-wrapper">
<div class="prompt-textarea-wrapper textarea-with-template">
<t-textarea
v-model="localSystemPromptNormal"
:autosize="{ minRows: 10, maxRows: 20 }"
@@ -274,32 +232,24 @@
@blur="handleSystemPromptNormalChange"
style="width: 100%; font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; font-size: 13px;"
/>
<PromptTemplateSelector
type="systemPrompt"
position="corner"
:hasKnowledgeBase="true"
@select="handleNormalSystemPromptTemplateSelect"
/>
</div>
</div>
</div>
<!-- Context Template(普通模式,自定义开关) -->
<!-- Context Template(普通模式) -->
<div class="setting-row vertical">
<div class="setting-info">
<label>{{ $t('conversationSettings.contextTemplate.label') }}</label>
<p class="desc">{{ $t('conversationSettings.contextTemplate.desc') }}</p>
<p class="desc">{{ $t('conversationSettings.contextTemplate.desc') }}(留空则使用系统默认)</p>
</div>
<div class="setting-control full-width">
<div class="prompt-header">
<div class="prompt-toggle">
<span class="prompt-toggle-label">{{ $t('conversationSettings.contextTemplate.custom') }}</span>
<t-switch
v-model="localUseCustomContextTemplate"
:label="[$t('common.off'), $t('common.on')]"
size="large"
@change="handleUseCustomContextTemplateToggle"
/>
</div>
</div>
<p v-if="!localUseCustomContextTemplate" class="prompt-disabled-hint">
{{ $t('conversationSettings.contextTemplate.disabledHint') }}
</p>
<div v-if="localUseCustomContextTemplate" class="prompt-textarea-wrapper">
<div class="prompt-textarea-wrapper textarea-with-template">
<t-textarea
v-model="localContextTemplate"
:autosize="{ minRows: 15, maxRows: 30 }"
@@ -307,6 +257,12 @@
@blur="handleContextTemplateChange"
style="width: 100%; font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; font-size: 13px;"
/>
<PromptTemplateSelector
type="contextTemplate"
position="corner"
:hasKnowledgeBase="true"
@select="handleContextTemplateTemplateSelect"
/>
</div>
</div>
</div>
@@ -540,11 +496,18 @@
<p class="desc">{{ $t('conversationSettings.rewritePrompt.desc') }}</p>
</div>
<div class="setting-control full-width">
<t-textarea
v-model="localRewritePromptSystem"
:autosize="{ minRows: 8, maxRows: 16 }"
@blur="handleRewritePromptSystemChange"
/>
<div class="textarea-with-template">
<t-textarea
v-model="localRewritePromptSystem"
:autosize="{ minRows: 8, maxRows: 16 }"
@blur="handleRewritePromptSystemChange"
/>
<PromptTemplateSelector
type="rewriteSystem"
position="corner"
@select="handleRewriteSystemTemplateSelect"
/>
</div>
</div>
</div>
@@ -554,11 +517,18 @@
<p class="desc">{{ $t('conversationSettings.rewritePrompt.userDesc') }}</p>
</div>
<div class="setting-control full-width">
<t-textarea
v-model="localRewritePromptUser"
:autosize="{ minRows: 8, maxRows: 16 }"
@blur="handleRewritePromptUserChange"
/>
<div class="textarea-with-template">
<t-textarea
v-model="localRewritePromptUser"
:autosize="{ minRows: 8, maxRows: 16 }"
@blur="handleRewritePromptUserChange"
/>
<PromptTemplateSelector
type="rewriteUser"
position="corner"
@select="handleRewriteUserTemplateSelect"
/>
</div>
</div>
</div>
@@ -583,26 +553,40 @@
<p class="desc">{{ $t('conversationSettings.fallbackResponse.desc') }}</p>
</div>
<div class="setting-control full-width">
<t-textarea
v-model="localFallbackResponse"
:autosize="{ minRows: 3, maxRows: 6 }"
@blur="handleFallbackResponseChange"
/>
<div class="textarea-with-template">
<t-textarea
v-model="localFallbackResponse"
:autosize="{ minRows: 3, maxRows: 6 }"
@blur="handleFallbackResponseChange"
/>
<PromptTemplateSelector
type="fallback"
position="corner"
@select="handleFallbackResponseTemplateSelect"
/>
</div>
</div>
</div>
<!-- 兜底 Prompt:仅在选择“交给模型继续生成”时展示 -->
<!-- 兜底 Prompt:仅在选择"交给模型继续生成"时展示 -->
<div v-else-if="localFallbackStrategy === 'model'" class="setting-row vertical">
<div class="setting-info">
<label>{{ $t('conversationSettings.fallbackPrompt.label') }}</label>
<p class="desc">{{ $t('conversationSettings.fallbackPrompt.desc') }}</p>
</div>
<div class="setting-control full-width">
<t-textarea
v-model="localFallbackPrompt"
:autosize="{ minRows: 8, maxRows: 16 }"
@blur="handleFallbackPromptChange"
/>
<div class="textarea-with-template">
<t-textarea
v-model="localFallbackPrompt"
:autosize="{ minRows: 8, maxRows: 16 }"
@blur="handleFallbackPromptChange"
/>
<PromptTemplateSelector
type="fallback"
position="corner"
@select="handleFallbackPromptTemplateSelect"
/>
</div>
</div>
</div>
@@ -659,6 +643,7 @@ import { MessagePlugin, DialogPlugin } from 'tdesign-vue-next'
import { useI18n } from 'vue-i18n'
import { listModels, type ModelConfig } from '@/api/model'
import { getAgentConfig, updateAgentConfig, getConversationConfig, updateConversationConfig, type AgentConfig, type ConversationConfig, type ToolDefinition, type PlaceholderDefinition } from '@/api/system'
import PromptTemplateSelector from '@/components/PromptTemplateSelector.vue'
const props = defineProps<{
// 来自外部设置弹窗的子菜单 key: 'modes' | 'models' | 'thresholds' | 'advanced'
@@ -680,8 +665,6 @@ const getDefaultConversationConfig = (): ConversationConfig => ({
context_template: '',
temperature: 0.3,
max_completion_tokens: 2048,
use_custom_system_prompt: true,
use_custom_context_template: true,
max_rounds: 5,
embedding_top_k: 10,
keyword_threshold: 0.3,
@@ -713,21 +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 localUseCustomSystemPrompt = ref(false)
// 统一系统提示词
const localSystemPrompt = ref('')
let savedSystemPrompt = ''
// 普通模式本地状态
const localContextTemplate = ref('')
@@ -755,10 +726,6 @@ const localRewritePromptUser = ref('')
const localSummaryModelId = ref('')
const localConversationRerankModelId = ref('')
// 普通模式 Prompt 是否自定义(关闭时使用系统默认)
const localUseCustomSystemPromptNormal = ref(true)
const localUseCustomContextTemplate = ref(true)
const syncConversationLocals = () => {
const cfg = conversationConfig.value
localContextTemplate.value = cfg.context_template ?? ''
@@ -785,8 +752,6 @@ const syncConversationLocals = () => {
localRewritePromptUser.value = cfg.rewrite_prompt_user ?? ''
localSummaryModelId.value = cfg.summary_model_id ?? ''
localConversationRerankModelId.value = cfg.rerank_model_id ?? ''
localUseCustomSystemPromptNormal.value = cfg.use_custom_system_prompt ?? true
localUseCustomContextTemplate.value = cfg.use_custom_context_template ?? true
settingsStore.updateConversationModels({
summaryModelId: localSummaryModelId.value || '',
@@ -835,9 +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,
use_custom_system_prompt: localUseCustomSystemPrompt.value,
system_prompt: localSystemPrompt.value,
...overrides,
})
@@ -916,9 +879,6 @@ const loadingConfig = ref(false)
const configLoaded = ref(false) // 防止重复加载
const isInitializing = ref(true) // 标记是否正在初始化,防止初始化时触发保存
// 保存的 Prompt 值,用于比较是否变化
let savedUseCustomSystemPrompt = false
// 恢复默认 Prompt 的加载状态
const isResettingPrompt = ref(false)
@@ -930,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(() => {
@@ -1049,15 +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 useCustomPrompt = config.use_custom_system_prompt ?? false
localUseCustomSystemPrompt.value = useCustomPrompt
savedUseCustomSystemPrompt = useCustomPrompt
const systemPrompt = config.system_prompt || ''
localSystemPrompt.value = systemPrompt
savedSystemPrompt = systemPrompt
availableTools.value = config.available_tools || []
availablePlaceholders.value = config.available_placeholders || []
@@ -1074,9 +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,
use_custom_system_prompt: useCustomPrompt
system_prompt: systemPrompt,
})
// 加载普通模式配置
@@ -1232,25 +1178,6 @@ const handleTemperatureChange = async (value: number) => {
}
}
// 切换是否启用自定义 Prompt
const handleUseCustomPromptToggle = async (value: boolean) => {
if (isInitializing.value) return
if (value === savedUseCustomSystemPrompt) return
try {
const config = buildAgentConfigPayload({ use_custom_system_prompt: value })
await updateAgentConfig(config)
savedUseCustomSystemPrompt = value
MessagePlugin.success(value ? t('agentSettings.toasts.customPromptEnabled') : t('agentSettings.toasts.defaultPromptEnabled'))
} catch (error) {
console.error('切换自定义 Prompt 失败:', error)
MessagePlugin.error(getErrorMessage(error))
// 回滚开关状态
localUseCustomSystemPrompt.value = savedUseCustomSystemPrompt
}
}
// 处理系统 Prompt 键盘事件(作为备用,主要逻辑在原生事件监听器中)
const handlePromptKeydown = (e: KeyboardEvent) => {
// 如果正在显示占位符提示,且输入的是字母、数字或下划线,实时更新过滤
@@ -1456,29 +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: '',
use_custom_system_prompt: false,
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 useCustom = res.data.use_custom_system_prompt ?? false
const defaultPrompt = res.data.system_prompt || ''
// 设置为默认 Prompt 的内容
localSystemPromptWebEnabled.value = defaultPromptWebEnabled
localSystemPromptWebDisabled.value = defaultPromptWebDisabled
savedSystemPromptMap['web-enabled'] = defaultPromptWebEnabled
savedSystemPromptMap['web-disabled'] = defaultPromptWebDisabled
localUseCustomSystemPrompt.value = useCustom
savedUseCustomSystemPrompt = useCustom
localSystemPrompt.value = defaultPrompt
savedSystemPrompt = defaultPrompt
MessagePlugin.success(t('agentSettings.toasts.resetToDefault'))
confirmDialog.hide()
@@ -1493,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
@@ -1515,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)
@@ -1559,7 +1475,6 @@ const handleContextTemplateChange = async () => {
await saveConversationConfig(
{
context_template: localContextTemplate.value,
use_custom_context_template: localUseCustomContextTemplate.value,
},
t('conversationSettings.toasts.contextTemplateSaved')
)
@@ -1576,66 +1491,6 @@ const reloadConversationConfig = async () => {
syncConversationLocals()
}
const handleUseCustomSystemPromptNormalToggle = async (value: boolean) => {
if (!conversationConfigLoaded.value) return
try {
if (!value) {
await saveConversationConfig(
{
prompt: '',
use_custom_system_prompt: false,
},
t('conversationSettings.toasts.defaultPromptEnabled')
)
await reloadConversationConfig()
} else {
await saveConversationConfig(
{
prompt: localSystemPromptNormal.value,
use_custom_system_prompt: true,
},
t('conversationSettings.toasts.customPromptEnabled')
)
savedSystemPromptNormal = localSystemPromptNormal.value
}
} catch (error) {
console.error('切换普通模式 System Prompt 自定义失败:', error)
MessagePlugin.error(getErrorMessage(error))
localUseCustomSystemPromptNormal.value = !value
}
}
const handleUseCustomContextTemplateToggle = async (value: boolean) => {
if (!conversationConfigLoaded.value) return
try {
if (!value) {
await saveConversationConfig(
{
context_template: '',
use_custom_context_template: false,
},
t('conversationSettings.toasts.defaultContextTemplateEnabled')
)
await reloadConversationConfig()
} else {
await saveConversationConfig(
{
context_template: localContextTemplate.value,
use_custom_context_template: true,
},
t('conversationSettings.toasts.customContextTemplateEnabled')
)
savedContextTemplate = localContextTemplate.value
}
} catch (error) {
console.error('切换普通模式 Context Template 自定义失败:', error)
MessagePlugin.error(getErrorMessage(error))
localUseCustomContextTemplate.value = !value
}
}
const handleSystemPromptNormalChange = async () => {
if (!conversationConfigLoaded.value) return
@@ -1647,7 +1502,6 @@ const handleSystemPromptNormalChange = async () => {
await saveConversationConfig(
{
prompt: localSystemPromptNormal.value,
use_custom_system_prompt: localUseCustomSystemPromptNormal.value,
},
t('conversationSettings.toasts.systemPromptSaved')
)
@@ -1813,6 +1667,35 @@ const handleFallbackPromptChange = async () => {
}
}
// 模板选择处理函数
const handleAgentSystemPromptTemplateSelect = (template: string) => {
localSystemPrompt.value = template
}
const handleNormalSystemPromptTemplateSelect = (template: string) => {
localSystemPromptNormal.value = template
}
const handleContextTemplateTemplateSelect = (template: string) => {
localContextTemplate.value = template
}
const handleRewriteSystemTemplateSelect = (template: string) => {
localRewritePromptSystem.value = template
}
const handleRewriteUserTemplateSelect = (template: string) => {
localRewritePromptUser.value = template
}
const handleFallbackResponseTemplateSelect = (template: string) => {
localFallbackResponse.value = template
}
const handleFallbackPromptTemplateSelect = (template: string) => {
localFallbackPrompt.value = template
}
const navigateToModelSettings = (subsection: 'chat' | 'rerank') => {
router.push('/platform/settings')
@@ -1881,9 +1764,29 @@ const handleConversationRerankModelChange = async (value: string) => {
.section-description {
font-size: 14px;
color: #666666;
margin: 0 0 20px 0;
margin: 0 0 12px 0;
line-height: 1.5;
}
.global-config-notice {
display: flex;
align-items: flex-start;
gap: 8px;
padding: 12px 16px;
background: #f0f9ff;
border: 1px solid #bae0ff;
border-radius: 8px;
margin-bottom: 20px;
color: #0958d9;
font-size: 13px;
line-height: 1.5;
.t-icon {
font-size: 16px;
flex-shrink: 0;
margin-top: 2px;
}
}
}
.agent-status-row {
@@ -2056,6 +1959,17 @@ const handleConversationRerankModelChange = async (value: string) => {
word-break: keep-all;
white-space: normal;
.setting-info-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 4px;
label {
margin-bottom: 0;
}
}
label {
font-size: 15px;
font-weight: 500;
@@ -2263,6 +2177,11 @@ const handleConversationRerankModelChange = async (value: string) => {
width: 100%;
}
.textarea-with-template {
position: relative;
width: 100%;
}
.setting-control.full-width {
display: flex;
flex-direction: column;
-17
View File
@@ -89,11 +89,6 @@
<OllamaSettings />
</div>
<!-- Agent 配置 -->
<div v-if="currentSection === 'agent'" class="section">
<AgentSettings :active-sub-section="currentSubSection || 'modes'" />
</div>
<!-- 网络搜索配置 -->
<div v-if="currentSection === 'websearch'" class="section">
<WebSearchSettings />
@@ -132,7 +127,6 @@ import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useUIStore } from '@/stores/ui'
import { useI18n } from 'vue-i18n'
import AgentSettings from './AgentSettings.vue'
import SystemInfo from './SystemInfo.vue'
import TenantInfo from './TenantInfo.vue'
import ApiInfo from './ApiInfo.vue'
@@ -165,17 +159,6 @@ const navItems = computed(() => [
]
},
{ key: 'ollama', icon: 'server', label: 'Ollama' },
{
key: 'agent',
icon: 'chat',
label: t('settings.conversationStrategy'),
children: [
{ key: 'modes', label: t('conversationSettings.menus.modes') },
{ key: 'models', label: t('conversationSettings.menus.models') },
{ key: 'thresholds', label: t('conversationSettings.menus.thresholds') },
{ key: 'advanced', label: t('conversationSettings.menus.advanced') },
]
},
{ key: 'websearch', icon: 'search', label: t('settings.webSearchConfig') },
{ key: 'mcp', icon: 'tools', label: t('settings.mcpService') },
{ key: 'system', icon: 'info-circle', label: t('settings.systemSettings') },