@@ -151,22 +151,51 @@
{ { $t ( 'common.resetToDefault' ) } }
< / t-button >
< / div >
< p class = "prompt-tab-hint" >
{ { $t ( 'agentSettings.systemPrompt.tabHint' ) } }
< / p >
< p v-if = "!localUseCustomSystemPrompt" class="prompt-disabled-hint" >
{ { $t ( 'agentSettings.systemPrompt.disabledHint' ) } }
< / p >
< div v-if = "localUseCustomSystemPrompt" class="prompt-textarea-wrapper " >
< t-textarea
ref = "promptTextareaRef "
v - model = "localS ystemP rompt"
: autosize = "{ minRows: 15, maxRows: 30 } "
: placeholder = "$t('agentSettings.systemPrompt.placeholder')"
@ blur = "handleSystemPromptChange"
@ input = "handlePromptInput"
@ keydown = "handlePromptKeydown"
: readonly = "!localUseCustomSystemPrompt "
: class = "{ 'prompt-textarea-readonly': !localUseCustom SystemPrompt } "
style = "width: 100%; font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; font-size: 13px; "
/ >
< div v-if = "localUseCustomSystemPrompt" class="system- prompt-tabs " >
< t-tabs
v - model = "activeSystemPromptTab "
class = "s ystem-p rompt-variant-tabs "
theme = "normal "
>
< 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 = "local SystemPromptWebEnabled "
: 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 >
<!-- 占位符提示下拉框 -- >
< teleport to = "body" >
@@ -580,11 +609,11 @@
< / div >
< div class = "setting-control" >
< t-input-number
v - model = "localMaxTokens"
v - model = "localMaxCompletion Tokens"
: min = "1"
: max = "100000"
: step = "100"
@ change = "handleMaxTokensChange"
@ change = "handleMaxCompletion TokensChange"
style = "width: 200px;"
/ >
< / div >
@@ -596,6 +625,7 @@
< script setup lang = "ts" >
import { ref , onMounted , watch , computed , nextTick } from 'vue'
import type { Ref } from 'vue'
import { useRouter } from 'vue-router'
import { useSettingsStore } from '@/stores/settings'
import { MessagePlugin , DialogPlugin } from 'tdesign-vue-next'
@@ -622,7 +652,7 @@ const getDefaultConversationConfig = (): ConversationConfig => ({
prompt : '' ,
context _template : '' ,
temperature : 0.3 ,
max _tokens : 2048 ,
max _completion _tokens : 2048 ,
use _custom _system _prompt : true ,
use _custom _context _template : true ,
max _rounds : 5 ,
@@ -656,18 +686,32 @@ const localTemperature = ref(0.7)
const localThinkingModelId = ref ( '' )
const localRerankModelId = ref ( '' )
const localAllowedTools = ref < string [ ] > ( [ ] )
const localSystemPrompt = ref ( '' )
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 localContextTemplate = ref ( '' )
const localSystemPromptNormal = ref ( '' )
const localTemperatureNormal = ref ( 0.3 )
const localMaxTokens = ref ( 2048 )
const localMaxCompletionTokens = ref ( 2048 )
let savedContextTemplate = ''
let savedSystemPromptNormal = ''
let savedTemperatureNormal = 0.3
let savedMaxTokens = 2048
let savedMaxCompletionTokens = 2048
const localMaxRounds = ref ( 5 )
const localEmbeddingTopK = ref ( 10 )
@@ -696,8 +740,8 @@ const syncConversationLocals = () => {
savedSystemPromptNormal = localSystemPromptNormal . value
localTemperatureNormal . value = cfg . temperature ? ? 0.3
savedTemperatureNormal = localTemperatureNormal . value
localMaxTokens . value = cfg . max _tokens ? ? 2048
savedMaxTokens = localMaxTokens . value
localMaxCompletionTokens . value = cfg . max _completion _tokens ? ? 2048
savedMaxCompletionTokens = localMaxCompletionTokens . value
localMaxRounds . value = cfg . max _rounds ? ? 5
localEmbeddingTopK . value = cfg . embedding _top _k ? ? 10
@@ -750,6 +794,20 @@ const isAgentReady = computed(() => {
localAllowedTools . value . length > 0
} )
const buildAgentConfigPayload = ( overrides : Partial < AgentConfig > = { } ) : AgentConfig => ( {
enabled : isAgentReady . value ,
max _iterations : localMaxIterations . value ,
reflection _enabled : false ,
allowed _tools : localAllowedTools . value ,
temperature : localTemperature . value ,
thinking _model _id : localThinkingModelId . value ,
rerank _model _id : localRerankModelId . value ,
system _prompt _web _enabled : localSystemPromptWebEnabled . value ,
system _prompt _web _disabled : localSystemPromptWebDisabled . value ,
use _custom _system _prompt : localUseCustomSystemPrompt . value ,
... overrides ,
} )
/ / A g e n t 状 态 提 示 消 息
const agentStatusMessage = computed ( ( ) => {
const missing : string [ ] = [ ]
@@ -787,7 +845,6 @@ const configLoaded = ref(false) // 防止重复加载
const isInitializing = ref ( true ) / / 标 记 是 否 正 在 初 始 化 , 防 止 初 始 化 时 触 发 保 存
/ / 保 存 的 P r o m p t 值 , 用 于 比 较 是 否 变 化
let savedSystemPrompt = ''
let savedUseCustomSystemPrompt = false
/ / 恢 复 默 认 P r o m p t 的 加 载 状 态
@@ -801,6 +858,12 @@ let placeholderPopupTimer: any = null
const placeholderPrefix = ref ( '' ) / / 当 前 输 入 的 前 缀 , 用 于 过 滤
const popupStyle = ref ( { top : '0px' , left : '0px' } ) / / 提 示 框 位 置
watch ( activeSystemPromptTab , ( ) => {
showPlaceholderPopup . value = false
placeholderPrefix . value = ''
selectedPlaceholderIndex . value = 0
} )
/ / 设 置 t e x t a r e a 原 生 事 件 监 听 器
const setupTextareaEventListeners = ( ) => {
nextTick ( ( ) => {
@@ -916,8 +979,12 @@ onMounted(async () => {
localThinkingModelId . value = config . thinking _model _id
localRerankModelId . value = config . rerank _model _id
localAllowedTools . value = config . allowed _tools || [ ]
localSystemPrompt . value = config . system _prompt || ''
savedSystemPrompt = config . system _prompt || '' / / 记 录 已 保 存 的 值
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
@@ -940,7 +1007,10 @@ onMounted(async () => {
temperature : config . temperature ,
thinkingModelId : config . thinking _model _id ,
rerankModelId : config . rerank _model _id ,
allowedTools : config . allowed _tools || [ ]
allowedTools : config . allowed _tools || [ ] ,
system _prompt _web _enabled : promptWebEnabled ,
system _prompt _web _disabled : promptWebDisabled ,
use _custom _system _prompt : useCustomPrompt
} )
/ / 加 载 普 通 模 式 配 置
@@ -1040,18 +1110,7 @@ const handleMaxIterationsChangeDebounced = (value: number) => {
}
try {
const config : AgentConfig = {
enabled : isAgentReady . value , / / 自 动 根 据 配 置 状 态 设 置
max _iterations : numValue , / / 确 保 是 数 字 类 型
reflection _enabled : false ,
allowed _tools : localAllowedTools . value ,
temperature : localTemperature . value ,
thinking _model _id : localThinkingModelId . value ,
rerank _model _id : localRerankModelId . value ,
system _prompt : localSystemPrompt . value ,
use _custom _system _prompt : localUseCustomSystemPrompt . value
}
const config = buildAgentConfigPayload ( { max _iterations : numValue } )
await updateAgentConfig ( config )
settingsStore . updateAgentConfig ( { maxIterations : numValue } )
lastSavedValue = numValue / / 记 录 已 保 存 的 值
@@ -1105,18 +1164,7 @@ const handleThinkingModelChange = async (value: string) => {
}
try {
const config : AgentConfig = {
enabled : isAgentReady . value , / / 自 动 根 据 配 置 状 态 设 置
max _iterations : localMaxIterations . value ,
reflection _enabled : false ,
allowed _tools : localAllowedTools . value ,
temperature : localTemperature . value ,
thinking _model _id : value ,
rerank _model _id : localRerankModelId . value ,
system _prompt : localSystemPrompt . value ,
use _custom _system _prompt : localUseCustomSystemPrompt . value
}
const config = buildAgentConfigPayload ( { thinking _model _id : value } )
await updateAgentConfig ( config )
/ / 更 新 s t o r e , 确 保 i s A g e n t R e a d y 能 正 确 计 算
settingsStore . updateAgentConfig ( { thinkingModelId : value } )
@@ -1140,18 +1188,7 @@ const handleRerankModelChange = async (value: string) => {
}
try {
const config : AgentConfig = {
enabled : isAgentReady . value , / / 自 动 根 据 配 置 状 态 设 置
max _iterations : localMaxIterations . value ,
reflection _enabled : false ,
allowed _tools : localAllowedTools . value ,
temperature : localTemperature . value ,
thinking _model _id : localThinkingModelId . value ,
rerank _model _id : value ,
system _prompt : localSystemPrompt . value ,
use _custom _system _prompt : localUseCustomSystemPrompt . value
}
const config = buildAgentConfigPayload ( { rerank _model _id : value } )
await updateAgentConfig ( config )
settingsStore . updateAgentConfig ( { rerankModelId : value } )
MessagePlugin . success ( t ( 'agentSettings.toasts.rerankModelSaved' ) )
@@ -1222,18 +1259,7 @@ const handleTemperatureChange = async (value: number) => {
if ( isInitializing . value ) return
try {
const config : AgentConfig = {
enabled : isAgentReady . value , / / 自 动 根 据 配 置 状 态 设 置
max _iterations : localMaxIterations . value ,
reflection _enabled : false ,
allowed _tools : localAllowedTools . value ,
temperature : value ,
thinking _model _id : localThinkingModelId . value ,
rerank _model _id : localRerankModelId . value ,
system _prompt : localSystemPrompt . value ,
use _custom _system _prompt : localUseCustomSystemPrompt . value
}
const config = buildAgentConfigPayload ( { temperature : value } )
await updateAgentConfig ( config )
settingsStore . updateAgentConfig ( { temperature : value } )
MessagePlugin . success ( t ( 'agentSettings.toasts.temperatureSaved' ) )
@@ -1249,18 +1275,7 @@ const handleAllowedToolsChange = async (value: string[]) => {
if ( isInitializing . value ) return
try {
const config : AgentConfig = {
enabled : isAgentReady . value , / / 自 动 根 据 配 置 状 态 设 置
max _iterations : localMaxIterations . value ,
reflection _enabled : false ,
allowed _tools : value ,
temperature : localTemperature . value ,
thinking _model _id : localThinkingModelId . value ,
rerank _model _id : localRerankModelId . value ,
system _prompt : localSystemPrompt . value ,
use _custom _system _prompt : localUseCustomSystemPrompt . value
}
const config = buildAgentConfigPayload ( { allowed _tools : value } )
await updateAgentConfig ( config )
settingsStore . updateAgentConfig ( { allowedTools : value } )
MessagePlugin . success ( t ( 'agentSettings.toasts.toolsUpdated' ) )
@@ -1278,18 +1293,7 @@ const handleUseCustomPromptToggle = async (value: boolean) => {
if ( value === savedUseCustomSystemPrompt ) return
try {
const config : AgentConfig = {
enabled : isAgentReady . value ,
max _iterations : localMaxIterations . value ,
reflection _enabled : false ,
allowed _tools : localAllowedTools . value ,
temperature : localTemperature . value ,
thinking _model _id : localThinkingModelId . value ,
rerank _model _id : localRerankModelId . value ,
system _prompt : localSystemPrompt . value ,
use _custom _system _prompt : value
}
const config = buildAgentConfigPayload ( { use _custom _system _prompt : value } )
await updateAgentConfig ( config )
savedUseCustomSystemPrompt = value
@@ -1331,7 +1335,8 @@ const filteredPlaceholders = computed(() => {
/ / 计 算 光 标 在 t e x t a r e a 中 的 像 素 位 置
const calculateCursorPosition = ( textarea : HTMLTextAreaElement ) => {
const cursorPos = textarea . selectionStart
const textBeforeCursor = localSystemPrompt . value . substring ( 0 , cursorPos )
const activePromptValue = getActivePromptRef ( ) . value
const textBeforeCursor = activePromptValue . substring ( 0 , cursorPos )
/ / 获 取 t e x t a r e a 的 样 式 和 位 置
const style = window . getComputedStyle ( textarea )
@@ -1383,7 +1388,7 @@ const checkAndShowPlaceholderPopup = () => {
}
const cursorPos = textarea . selectionStart
const textBeforeCursor = localSystemPrompt . value . substring ( 0 , cursorPos )
const textBeforeCursor = getActivePromptRef ( ) . value . substring ( 0 , cursorPos )
/ / 检 查 是 否 输 入 了 { { ( 从 光 标 位 置 向 前 查 找 最 近 的 { { )
/ / 需 要 找 到 光 标 前 最 近 的 { { , 且 中 间 没 有 } }
@@ -1463,15 +1468,17 @@ const insertPlaceholder = (placeholderName: string) => {
/ / 延 迟 执 行 , 确 保 提 示 框 已 关 闭
nextTick ( ( ) => {
const cursorPos = textarea . selectionStart
const textBeforeCursor = localSystemPrompt . value . substring ( 0 , cursorPos )
const textAfterCursor = localSystemPrompt . value . substring ( cursorPos )
const promptRef = getActivePromptRef ( )
const currentValue = promptRef . value
const textBeforeCursor = currentValue . substring ( 0 , cursorPos )
const textAfterCursor = currentValue . substring ( cursorPos )
/ / 找 到 最 后 一 个 { { 的 位 置
const lastOpenPos = textBeforeCursor . lastIndexOf ( '{{' )
if ( lastOpenPos === - 1 ) {
/ / 如 果 没 有 找 到 { { , 直 接 插 入 完 整 的 占 位 符
const placeholder = ` {{ ${ placeholderName } }} `
localSystemPrompt . value = textBeforeCursor + placeholder + textAfterCursor
promptRef . value = textBeforeCursor + placeholder + textAfterCursor
/ / 设 置 光 标 位 置
nextTick ( ( ) => {
const newPos = cursorPos + placeholder . length
@@ -1482,7 +1489,7 @@ const insertPlaceholder = (placeholderName: string) => {
/ / 替 换 { { 到 光 标 位 置 的 内 容 为 完 整 的 占 位 符
const beforePlaceholder = textBeforeCursor . substring ( 0 , lastOpenPos )
const placeholder = ` {{ ${ placeholderName } }} `
localSystemPrompt . value = beforePlaceholder + placeholder + textAfterCursor
promptRef . value = beforePlaceholder + placeholder + textAfterCursor
/ / 设 置 光 标 位 置
nextTick ( ( ) => {
const newPos = lastOpenPos + placeholder . length
@@ -1504,30 +1511,27 @@ const handleResetToDefault = async () => {
try {
isResettingPrompt . value = true
/ / 通 过 设 置 s y s t e m _ p r o m p t 为 空 字 符 串 来 获 取 默 认 值
/ / 后 端 在 s y s t e m _ p r o m p t 为 空 时 会 返 回 默 认 值
const tempConfig : AgentConfig = {
enabled : isAgentReady . value ,
max _iterations : localMaxIterations . value ,
reflection _enabled : false ,
allowed _tools : localAllowedTools . value ,
temperature : localTemperature . value ,
thinking _model _id : localThinkingModelId . value ,
rerank _model _id : localRerankModelId . value ,
system _prompt : '' , / / 空 字 符 串 表 示 使 用 默 认
use _custom _system _prompt : false
}
/ / 通 过 设 置 s y s t e m _ p r o m p t _ w e b _ * 为 空 字 符 串 来 获 取 默 认 值
/ / 后 端 在 字 段 为 空 时 会 返 回 默 认 值
const tempConfig = buildAgentConfigPayload ( {
system _prompt _web _enabled : '' ,
system _prompt _web _disabled : '' ,
use _custom _system _prompt : false ,
} )
await updateAgentConfig ( tempConfig )
/ / 重 新 加 载 配 置 以 获 取 默 认 P r o m p t 的 完 整 内 容
const res = await getAgentConfig ( )
const defaultPrompt = res . data . system _prompt || ''
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
/ / 设 置 为 默 认 P r o m p t 的 内 容
localSystemPrompt . value = defaultPrompt
savedSystemPrompt = defaultPrompt
localSystemPromptWebEnabled . value = defaultPromptWebEnabled
localSystemPromptWebDisabled . value = defaultPromptWebDisabled
savedSystemPromptMap [ 'web-enabled' ] = defaultPromptWebEnabled
savedSystemPromptMap [ 'web-disabled' ] = defaultPromptWebDisabled
localUseCustomSystemPrompt . value = useCustom
savedUseCustomSystemPrompt = useCustom
@@ -1544,7 +1548,7 @@ const handleResetToDefault = async () => {
}
/ / 处 理 系 统 P r o m p t 变 化
const handleSystemPromptChange = async ( e ? : FocusEvent ) => {
const handleSystemPromptChange = async ( tab : SystemPromptTab , e ? : FocusEvent ) => {
/ / 如 果 点 击 的 是 占 位 符 提 示 框 , 不 触 发 保 存
if ( e ? . relatedTarget ) {
const target = e . relatedTarget as HTMLElement
@@ -1567,26 +1571,18 @@ const handleSystemPromptChange = async (e?: FocusEvent) => {
/ / 如 果 正 在 初 始 化 , 不 触 发 保 存
if ( isInitializing . value ) return
const promptRef = getPromptRefByTab ( tab )
const savedValue = savedSystemPromptMap [ tab ]
/ / 检 查 内 容 是 否 变 化
if ( localSystemPrompt . value === savedSystemPrompt ) {
if ( promptRef . value === savedValue ) {
return / / 内 容 没 变 , 不 调 用 接 口
}
try {
const config : AgentConfig = {
enabled : isAgentReady . value ,
max _iterations : localMaxIterations . value ,
reflection _enabled : false ,
allowed _tools : localAllowedTools . value ,
temperature : localTemperature . value ,
thinking _model _id : localThinkingModelId . value ,
rerank _model _id : localRerankModelId . value ,
system _prompt : localSystemPrompt . value ,
use _custom _system _prompt : localUseCustomSystemPrompt . value
}
const config = buildAgentConfigPayload ( )
await updateAgentConfig ( config )
savedSystemPrompt = localSystemPrompt . value / / 更 新 已 保 存 的 值
savedSystemPromptMap [ tab ] = promptRef . value / / 更 新 已 保 存 的 值
MessagePlugin . success ( t ( 'agentSettings.toasts.systemPromptSaved' ) )
} catch ( error ) {
console . error ( '保存系统 Prompt 失败:' , error )
@@ -1732,15 +1728,15 @@ const handleTemperatureNormalChange = async (value: number) => {
}
}
const handleMaxTokensChange = async ( value : number ) => {
const handleMaxCompletionTokensChange = async ( value : number ) => {
if ( ! conversationConfigLoaded . value ) return
try {
await saveConversationConfig (
{ max _tokens : value } ,
{ max _completion _tokens : value } ,
t ( 'conversationSettings.toasts.maxTokensSaved' )
)
savedMaxTokens = value
savedMaxCompletionTokens = value
} catch ( error ) {
console . error ( '保存Max Tokens失败:' , error )
MessagePlugin . error ( getErrorMessage ( error ) )
@@ -2214,6 +2210,39 @@ const handleConversationRerankModelChange = async (value: string) => {
font - size : 12 px ;
}
. prompt - tab - hint {
margin : 0 0 12 px ;
color : # 666 ;
font - size : 12 px ;
}
. system - prompt - tabs {
width : 100 % ;
}
. system - prompt - variant - tabs : deep ( . t - tabs _ _nav - wrap ) {
border - bottom : 1 px solid # e5e7eb ;
margin - bottom : 8 px ;
}
. system - prompt - variant - tabs : deep ( . t - tabs _ _nav - item ) {
padding : 4 px 12 px 10 px ;
font - size : 13 px ;
color : # 666 ;
border - bottom : 2 px solid transparent ;
transition : color 0.2 s ease , border - color 0.2 s ease ;
}
. system - prompt - variant - tabs : deep ( . t - tabs _ _nav - item . t - is - active ) {
color : # 1 d2129 ;
border - bottom - color : # 07 C05F ;
font - weight : 600 ;
}
. system - prompt - variant - tabs : deep ( . t - tabs _ _bar ) {
display : none ;
}
. prompt - textarea - readonly {
background - color : # fafafa ;
}