@@ -222,6 +222,68 @@
< / div >
< / div >
<!-- 意图提示词 ( 仅普通模式 , 放在上下文模板下方 ) -- >
< div v-if = "!isAgentMode" class="setting-row setting-row-vertical" >
< div class = "setting-info" >
< label > { { $t ( 'agentEditor.intentPrompts.title' ) } } < / label >
< / div >
< div class = "setting-control setting-control-full" >
< div class = "intent-prompts-editor" >
< div class = "intent-selector-row" >
< span class = "intent-label" > { { $t ( 'agentEditor.intentPrompts.intentLabel' ) } } < / span >
< t-select v-model = "selectedIntent" size = "small"
: disabled = "props.readOnly || intentPromptTemplates.length === 0" class = "intent-select" >
< t-option v-for = "template in intentPromptTemplates" :key = "template.id"
: value = "template.id" : label = "template.name || template.id" >
{ { template . name || template . id } }
< / t-option >
< / t-select >
< span v-if = "currentIntentTemplateDesc" class="intent-desc" > {{ currentIntentTemplateDesc
} } < / span >
< / div >
< div v-if = "placeholderData.system_prompt.length > 0" class="placeholder-tags" >
< span class = "placeholder-label" > { { $t ( 'agentEditor.placeholders.available' ) } } < / span >
< t-tooltip v-for = "placeholder in placeholderData.system_prompt" :key = "placeholder.name"
: content = "placeholder.description + $t('agentEditor.placeholders.clickToInsert')"
placement = "top" >
< span class = "placeholder-tag" @ click = "handlePlaceholderClick('intent', placeholder.name)"
v - text = "'{{' + placeholder.name + '}}'" / >
< / t-tooltip >
< span class = "placeholder-hint" > { { $t ( 'agentEditor.placeholders.hint' ) } } < / span >
< / div >
< div class = "textarea-with-template" >
< t-textarea ref = "intentPromptTextareaRef" v -model = " intentEditorValue "
class = "system-prompt-textarea" : autosize = "{ minRows: 10, maxRows: 25 }"
: disabled = "props.readOnly || !selectedIntent"
: placeholder = "currentIntentTemplate?.content || $t('agentEditor.intentPrompts.promptPlaceholder')"
@ input = "handleIntentPromptInput" / >
< PromptTemplateSelector type = "intentPrompt" position = "corner" :intent-id = "selectedIntent"
: show - template - picker = "false" @ reset - default = "resetCurrentIntentPrompt" / >
< / div >
< Teleport to = "body" >
< div v -if = " intentPromptPopup.show & & filteredIntentPlaceholders.length > 0 "
class = "placeholder-popup-wrapper" : style = "intentPromptPopup.style" >
< div class = "placeholder-popup" >
< div v-for = "(placeholder, index) in filteredIntentPlaceholders" :key = "placeholder.name"
class = "placeholder-item"
: class = "{ active: intentPromptPopup.selectedIndex === index }"
@ mousedown . prevent = "insertGenericPlaceholder('intent', placeholder.name, true)"
@ mouseenter = "intentPromptPopup.selectedIndex = index" >
< div class = "placeholder-name" >
< code v-html = "`{{${placeholder.name}}}`" / >
< / div >
< div class = "placeholder-desc" > { { placeholder . description } } < / div >
< / div >
< / div >
< / div >
< / Teleport >
< / div >
< / div >
< / div >
< / div >
< / div >
@@ -1289,6 +1351,7 @@ const kbOptions = ref<{ label: string; value: string; type?: 'document' | 'faq';
const agentTypePresets = ref < AgentTypePreset [ ] > ( [ ] ) ;
/ / A g e n t 系 统 提 示 词 模 板 缓 存 ( 用 于 切 换 智 能 体 类 型 时 根 据 s y s t e m _ p r o m p t _ i d 解 析 出 实 际 文 本 填 入 )
const agentSystemPromptTemplates = ref < PromptTemplate [ ] > ( [ ] ) ;
const intentPromptTemplates = ref < PromptTemplate [ ] > ( [ ] ) ;
const mcpOptions = ref < { label : string ; value : string } [ ] > ( [ ] ) ;
const webSearchProviderList = ref < WebSearchProviderEntity [ ] > ( [ ] ) ;
const skillOptions = ref < { name : string ; description : string } [ ] > ( [ ] ) ;
@@ -1594,6 +1657,12 @@ const contextPlaceholderPrefix = ref('');
const contextPopupStyle = ref ( { top : '0px' , left : '0px' } ) ;
let contextPlaceholderPopupTimer : any = null ;
/ / 意 图 提 示 词 编 辑 相 关
const selectedIntent = ref ( '' ) ;
const intentEditorValue = ref ( '' ) ;
const intentPromptsSyncing = ref ( false ) ;
const intentPromptTextareaRef = ref < any > ( null ) ;
/ / 通 用 占 位 符 弹 出 相 关 ( 用 于 改 写 提 示 词 和 兜 底 提 示 词 )
interface PlaceholderPopupState {
show : boolean ;
@@ -1605,6 +1674,10 @@ interface PlaceholderPopupState {
placeholders : PlaceholderDefinition [ ] ;
}
const intentPromptPopup = ref < PlaceholderPopupState > ( {
show : false , selectedIndex : 0 , prefix : '' , style : { top : '0px' , left : '0px' } , timer : null , fieldKey : 'intent_prompt' , placeholders : [ ]
} ) ;
const rewriteSystemPopup = ref < PlaceholderPopupState > ( {
show : false , selectedIndex : 0 , prefix : '' , style : { top : '0px' , left : '0px' } , timer : null , fieldKey : 'rewrite_prompt_system' , placeholders : [ ]
} ) ;
@@ -1740,6 +1813,94 @@ const agentMode = computed({
const isAgentMode = computed ( ( ) => agentMode . value === 'smart-reasoning' ) ;
const currentIntentTemplate = computed ( ( ) =>
intentPromptTemplates . value . find ( ( template ) => template . id === selectedIntent . value ) ,
) ;
const currentIntentTemplateDesc = computed ( ( ) =>
currentIntentTemplate . value ? . description || t ( 'agentEditor.intentPrompts.intentDescription' ) ,
) ;
const filteredIntentPlaceholders = computed ( ( ) => {
if ( ! intentPromptPopup . value . prefix ) {
return placeholderData . value . system _prompt ;
}
const prefix = intentPromptPopup . value . prefix . toLowerCase ( ) ;
return placeholderData . value . system _prompt . filter ( p => p . name . toLowerCase ( ) . startsWith ( prefix ) ) ;
} ) ;
const syncIntentEditorFromSelection = ( ) => {
const key = selectedIntent . value ;
if ( ! key ) {
intentEditorValue . value = '' ;
return ;
}
const overrides = formData . value . config . intent _prompts || { } ;
intentEditorValue . value = overrides [ key ] ? ? currentIntentTemplate . value ? . content ? ? '' ;
} ;
watch ( selectedIntent , ( ) => {
intentPromptPopup . value . show = false ;
intentPromptPopup . value . prefix = '' ;
syncIntentEditorFromSelection ( ) ;
} ) ;
watch (
( ) => intentPromptTemplates . value ,
( templates ) => {
if ( ! selectedIntent . value && templates . length > 0 ) {
selectedIntent . value = templates [ 0 ] . id ;
} else if ( selectedIntent . value ) {
syncIntentEditorFromSelection ( ) ;
}
} ,
{ immediate : true } ,
) ;
watch ( intentEditorValue , ( value ) => {
const key = selectedIntent . value ;
if ( ! key || intentPromptsSyncing . value ) return ;
const defaultContent = currentIntentTemplate . value ? . content || '' ;
const next = value . trim ( ) ;
if ( ! next || next === defaultContent . trim ( ) ) {
if ( formData . value . config . intent _prompts ) {
const { [ key ] : _removed , ... rest } = formData . value . config . intent _prompts ;
if ( Object . keys ( rest ) . length === 0 ) {
delete formData . value . config . intent _prompts ;
} else {
formData . value . config . intent _prompts = rest ;
}
}
return ;
}
formData . value . config . intent _prompts = {
... ( formData . value . config . intent _prompts || { } ) ,
[ key ] : value ,
} ;
} ) ;
watch (
( ) => formData . value . config . intent _prompts ,
( ) => {
intentPromptsSyncing . value = true ;
syncIntentEditorFromSelection ( ) ;
intentPromptsSyncing . value = false ;
} ,
{ deep : true } ,
) ;
const resetCurrentIntentPrompt = ( ) => {
const key = selectedIntent . value ;
if ( ! key || ! formData . value . config . intent _prompts ) return ;
const { [ key ] : _removed , ... rest } = formData . value . config . intent _prompts ;
if ( Object . keys ( rest ) . length === 0 ) {
delete formData . value . config . intent _prompts ;
} else {
formData . value . config . intent _prompts = rest ;
}
syncIntentEditorFromSelection ( ) ;
} ;
/ / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
/ / 智 能 体 类 型 预 设 ( 仅 s m a r t - r e a s o n i n g 模 式 下 可 见 )
/ / 选 择 类 型 后 自 动 填 充 s y s t e m _ p r o m p t _ i d / a l l o w e d _ t o o l s 等 ;
@@ -2496,6 +2657,9 @@ const loadDependencies = async () => {
if ( fixedFallback ? . content ) defaultFallbackResponse . value = fixedFallback . content ;
const modelFallback = fallbackList . find ( t => t . mode === 'model' && t . default ) || fallbackList . find ( t => t . mode === 'model' ) ;
if ( modelFallback ? . content ) defaultFallbackPrompt . value = modelFallback . content ;
if ( Array . isArray ( cfg ? . intent _prompts ) ) {
intentPromptTemplates . value = cfg . intent _prompts ;
}
} catch ( e ) {
console . warn ( 'Failed to load prompt templates' , e ) ;
}
@@ -2523,7 +2687,7 @@ const loadDependencies = async () => {
/ / 加 载 占 位 符 定 义 ( 从 统 一 A P I )
try {
const placeholdersRes = await getPlaceholders ( ) ;
if ( placeholdersRes . data ) {
if ( placeholdersRes ? . data ) {
placeholderData . value = placeholdersRes . data ;
}
} catch ( e ) {
@@ -2557,6 +2721,7 @@ const handleAddModel = (subSection: string) => {
const handleClose = ( ) => {
showPlaceholderPopup . value = false ;
showContextPlaceholderPopup . value = false ;
intentPromptPopup . value . show = false ;
rewriteSystemPopup . value . show = false ;
rewriteUserPopup . value . show = false ;
fallbackPromptPopup . value . show = false ;
@@ -2928,12 +3093,34 @@ const insertContextPlaceholder = (placeholderName: string, fromPopup: boolean =
} ) ;
} ;
type GenericPlaceholderType = 'rewriteSystem' | 'rewriteUser' | 'fallback' | 'intent' ;
const genericPlaceholderFieldKeyMap : Record < Exclude < GenericPlaceholderType , ' intent ' > , keyof typeof formData . value . config > = {
rewriteSystem : 'rewrite_prompt_system' ,
rewriteUser : 'rewrite_prompt_user' ,
fallback : 'fallback_prompt' ,
} ;
const getGenericPlaceholderFieldValue = ( type : GenericPlaceholderType ) : string => {
if ( type === 'intent' ) return intentEditorValue . value || '' ;
return String ( formData . value . config [ genericPlaceholderFieldKeyMap [ type ] ] || '' ) ;
} ;
const setGenericPlaceholderFieldValue = ( type : GenericPlaceholderType , value : string ) => {
if ( type === 'intent' ) {
intentEditorValue . value = value ;
return ;
}
( formData . value . config as any ) [ genericPlaceholderFieldKeyMap [ type ] ] = value ;
} ;
/ / 通 用 获 取 t e x t a r e a 元 素
const getGenericTextareaElement = ( type : 'rewriteSystem' | 'rewriteUser' | 'fallback' ) : HTMLTextAreaElement | null => {
const getGenericTextareaElement = ( type : GenericPlaceholderType ) : HTMLTextAreaElement | null => {
const refMap = {
rewriteSystem : rewriteSystemTextareaRef ,
rewriteUser : rewriteUserTextareaRef ,
fallback : fallbackPromptTextareaRef ,
intent : intentPromptTextareaRef ,
} ;
const ref = refMap [ type ] ;
if ( ref . value ) {
@@ -2982,16 +3169,15 @@ const calculateGenericCursorPosition = (textarea: HTMLTextAreaElement, fieldValu
/ / 通 用 检 查 并 显 示 占 位 符 弹 出
const checkAndShowGenericPlaceholderPopup = (
type : 'rewriteSystem' | 'rewriteUser' | 'fallback' ,
type : GenericPlaceholderType ,
popup : typeof rewriteSystemPopup ,
fieldKey : keyof typeof formData . value . config ,
filteredPlaceholders : PlaceholderDefinition [ ]
) => {
const textarea = getGenericTextareaElement ( type ) ;
if ( ! textarea ) return ;
const cursorPos = textarea . selectionStart ;
const fieldValue = String ( formData . value . config [ fieldKey ] || '' ) ;
const fieldValue = getGenericPlaceholderFieldValue ( type ) ;
const textBeforeCursor = fieldValue . substring ( 0 , cursorPos ) ;
let lastOpenPos = - 1 ;
@@ -3035,7 +3221,7 @@ const handleRewriteSystemInput = () => {
clearTimeout ( rewriteSystemPopup . value . timer ) ;
}
rewriteSystemPopup . value . timer = setTimeout ( ( ) => {
checkAndShowGenericPlaceholderPopup ( 'rewriteSystem' , rewriteSystemPopup , 'rewrite_prompt_system' , filteredRewriteSystemPlaceholders . value ) ;
checkAndShowGenericPlaceholderPopup ( 'rewriteSystem' , rewriteSystemPopup , filteredRewriteSystemPlaceholders . value ) ;
} , 50 ) ;
} ;
@@ -3045,7 +3231,7 @@ const handleRewriteUserInput = () => {
clearTimeout ( rewriteUserPopup . value . timer ) ;
}
rewriteUserPopup . value . timer = setTimeout ( ( ) => {
checkAndShowGenericPlaceholderPopup ( 'rewriteUser' , rewriteUserPopup , 'rewrite_prompt_user' , filteredRewriteUserPlaceholders . value ) ;
checkAndShowGenericPlaceholderPopup ( 'rewriteUser' , rewriteUserPopup , filteredRewriteUserPlaceholders . value ) ;
} , 50 ) ;
} ;
@@ -3055,12 +3241,22 @@ const handleFallbackPromptInput = () => {
clearTimeout ( fallbackPromptPopup . value . timer ) ;
}
fallbackPromptPopup . value . timer = setTimeout ( ( ) => {
checkAndShowGenericPlaceholderPopup ( 'fallback' , fallbackPromptPopup , 'fallback_prompt' , filteredFallbackPlaceholders . value ) ;
checkAndShowGenericPlaceholderPopup ( 'fallback' , fallbackPromptPopup , filteredFallbackPlaceholders . value ) ;
} , 50 ) ;
} ;
/ / 处 理 意 图 提 示 词 输 入
const handleIntentPromptInput = ( ) => {
if ( intentPromptPopup . value . timer ) {
clearTimeout ( intentPromptPopup . value . timer ) ;
}
intentPromptPopup . value . timer = setTimeout ( ( ) => {
checkAndShowGenericPlaceholderPopup ( 'intent' , intentPromptPopup , filteredIntentPlaceholders . value ) ;
} , 50 ) ;
} ;
/ / 通 用 插 入 占 位 符
const insertGenericPlaceholder = ( type : 'rewriteSystem' | 'rewriteUser' | 'fallback' , placeholderName : string , fromPopup : boolean = false ) => {
const insertGenericPlaceholder = ( type : GenericPlaceholderType , placeholderName : string , fromPopup : boolean = false ) => {
const textarea = getGenericTextareaElement ( type ) ;
if ( ! textarea ) return ;
@@ -3068,15 +3264,10 @@ const insertGenericPlaceholder = (type: 'rewriteSystem' | 'rewriteUser' | 'fallb
rewriteSystem : rewriteSystemPopup ,
rewriteUser : rewriteUserPopup ,
fallback : fallbackPromptPopup ,
} ;
const fieldKeyMap : Record < string , keyof typeof formData.value.config > = {
rewriteSystem : 'rewrite_prompt_system' ,
rewriteUser : 'rewrite_prompt_user' ,
fallback : 'fallback_prompt' ,
intent : intentPromptPopup ,
} ;
const popup = popupMap [ type ] ;
const fieldKey = fieldKeyMap [ type ] ;
popup . value . show = false ;
popup . value . prefix = '' ;
@@ -3084,7 +3275,7 @@ const insertGenericPlaceholder = (type: 'rewriteSystem' | 'rewriteUser' | 'fallb
nextTick ( ( ) => {
const cursorPos = textarea . selectionStart ;
const currentValue = String ( formData . value . config [ fieldKey ] || '' ) ;
const currentValue = getGenericPlaceholderFieldValue ( type ) ;
const textBeforeCursor = currentValue . substring ( 0 , cursorPos ) ;
const textAfterCursor = currentValue . substring ( cursorPos ) ;
@@ -3101,7 +3292,7 @@ const insertGenericPlaceholder = (type: 'rewriteSystem' | 'rewriteUser' | 'fallb
if ( lastOpenPos !== - 1 ) {
const textBeforeOpen = currentValue . substring ( 0 , lastOpenPos ) ;
const newValue = textBeforeOpen + ` {{ ${ placeholderName } }} ` + textAfterCursor ;
( formData . value . config as any ) [ fieldKey ] = newValue ;
setGenericPlaceholderFieldValue ( type , newValue ) ;
nextTick ( ( ) => {
const newCursorPos = textBeforeOpen . length + placeholderName . length + 4 ;
@@ -3114,7 +3305,7 @@ const insertGenericPlaceholder = (type: 'rewriteSystem' | 'rewriteUser' | 'fallb
/ / 直 接 在 光 标 位 置 插 入 完 整 占 位 符
const newValue = textBeforeCursor + ` {{ ${ placeholderName } }} ` + textAfterCursor ;
( formData . value . config as any ) [ fieldKey ] = newValue ;
setGenericPlaceholderFieldValue ( type , newValue ) ;
nextTick ( ( ) => {
const newCursorPos = cursorPos + placeholderName . length + 4 ;
@@ -3210,7 +3401,7 @@ const setupTextareaEventListeners = () => {
/ / 通 用 设 置 t e x t a r e a 事 件 监 听
const setupGenericTextareaEventListeners = (
type : 'rewriteSystem' | 'rewriteUser' | 'fallback' ,
type : GenericPlaceholderType ,
popup : typeof rewriteSystemPopup ,
filteredPlaceholders : ( ) => PlaceholderDefinition [ ]
) => {
@@ -3256,7 +3447,7 @@ const setupGenericTextareaEventListeners = (
} ;
/ / 处 理 点 击 占 位 符 标 签
const handlePlaceholderClick = ( type : 'system' | 'context' | 'rewriteSystem' | 'rewriteUser' | 'fallback' , placeholderName : string ) => {
const handlePlaceholderClick = ( type : 'system' | 'context' | 'rewriteSystem' | 'rewriteUser' | 'fallback' | 'intent' , placeholderName : string ) => {
if ( type === 'system' ) {
insertPlaceholder ( placeholderName ) ;
} else if ( type === 'context' ) {
@@ -3272,6 +3463,7 @@ watch(() => props.visible, (val) => {
nextTick ( ( ) => {
setupTextareaEventListeners ( ) ;
setupContextTemplateEventListeners ( ) ;
setupGenericTextareaEventListeners ( 'intent' , intentPromptPopup , ( ) => filteredIntentPlaceholders . value ) ;
setupGenericTextareaEventListeners ( 'rewriteSystem' , rewriteSystemPopup , ( ) => filteredRewriteSystemPlaceholders . value ) ;
setupGenericTextareaEventListeners ( 'rewriteUser' , rewriteUserPopup , ( ) => filteredRewriteUserPlaceholders . value ) ;
setupGenericTextareaEventListeners ( 'fallback' , fallbackPromptPopup , ( ) => filteredFallbackPlaceholders . value ) ;
@@ -3408,6 +3600,10 @@ const handleSave = async () => {
formData . value . config . suggested _prompts = formData . value . config . suggested _prompts . filter ( ( p : string ) => p . trim ( ) !== '' ) ;
}
if ( ! formData . value . config . intent _prompts || Object . keys ( formData . value . config . intent _prompts ) . length === 0 ) {
delete formData . value . config . intent _prompts ;
}
saving . value = true ;
try {
if ( props . mode === 'create' ) {
@@ -4260,6 +4456,35 @@ const handleSave = async () => {
width : 100 % ;
}
. intent - prompts - editor {
width : 100 % ;
display : flex ;
flex - direction : column ;
gap : 8 px ;
}
. intent - selector - row {
display : flex ;
align - items : center ;
gap : 12 px ;
flex - wrap : wrap ;
}
. intent - label {
font - size : 12 px ;
color : var ( -- td - text - color - secondary ) ;
}
. intent - select {
width : 150 px ;
}
. intent - desc {
font - size : 12 px ;
color : var ( -- td - text - color - placeholder ) ;
line - height : 1.4 ;
}
/ / 系 统 提 示 词 输 入 框 样 式
. system - prompt - textarea {
width : 100 % ;