@@ -2,9 +2,7 @@ import { toRaw } from 'vue'
22import useMcpServer from './useMcp'
33import type { LLMMessage , RobotMessage } from './types'
44import type { LLMRequestBody , LLMResponse , ReponseToolCall , RequestOptions , RequestTool } from './types'
5- import { META_SERVICE , getMetaApi , getOptions } from '@opentiny/tiny-engine-meta-register'
6- import systemPrompt from '../system-prompt.md?raw'
7- import meta from '../../meta'
5+ import { META_SERVICE , getMetaApi } from '@opentiny/tiny-engine-meta-register'
86
97let requestOptions : RequestOptions = { }
108
@@ -33,48 +31,6 @@ const fetchLLM = async (messages: LLMMessage[], tools: RequestTool[], options: R
3331 } )
3432}
3533
36- // 计算当前生效的 system prompt(支持注册表覆盖与关闭)
37- const getEffectiveSystemPrompt = ( ) : { disabled : boolean ; prompt ?: string } => {
38- try {
39- const options = getOptions && typeof getOptions === 'function' ? getOptions ( ( meta as any ) ?. id ) : undefined
40- const disabled = options ?. disableSystemPrompt === true
41- if ( disabled ) {
42- return { disabled : true }
43- }
44- const custom = options ?. customSystemPrompt
45- const prompt = typeof custom === 'string' && custom . trim ( ) . length > 0 ? custom : systemPrompt
46- return { disabled : false , prompt }
47- } catch ( _err ) {
48- // 安全回退到内置 system prompt
49- return { disabled : false , prompt : systemPrompt }
50- }
51- }
52-
53- // 确保 system prompt 仅注入一次,并作为首条历史消息(仅限 MCP 路径)
54- const withSystemPromptOnce = ( messages : LLMMessage [ ] ) : LLMMessage [ ] => {
55- const { disabled, prompt } = getEffectiveSystemPrompt ( )
56- if ( disabled ) {
57- return messages
58- }
59-
60- // 正常情况下 prompt 一定存在;若异常则透传
61- if ( ! prompt ) {
62- return messages
63- }
64-
65- if ( ! messages . length ) {
66- return [ { role : 'system' , content : prompt } ]
67- }
68- const first = messages [ 0 ]
69- if ( first . role === 'system' ) {
70- // 若首条已为 system:
71- // - 与当前生效 prompt 全等:直接返回
72- // - 不等:尊重现有会话,不做热替换,避免双 system
73- return first . content === prompt ? messages : messages
74- }
75- return [ { role : 'system' , content : prompt } , ...messages ]
76- }
77-
7834const parseArgs = ( args : string ) => {
7935 try {
8036 return JSON . parse ( args )
@@ -155,12 +111,11 @@ const handleToolCall = async (
155111 }
156112 }
157113 currentMessage . renderContent . push ( { type : 'loading' , content : '' } )
158- const preppedToolMessages = withSystemPromptOnce ( toolMessages )
159- const newResp = await fetchLLM ( preppedToolMessages , tools )
114+ const newResp = await fetchLLM ( toolMessages , tools )
160115 currentMessage . renderContent . pop ( )
161116 const hasToolCall = newResp . choices [ 0 ] . message . tool_calls ?. length > 0
162117 if ( hasToolCall ) {
163- await handleToolCall ( newResp , tools , messages , preppedToolMessages )
118+ await handleToolCall ( newResp , tools , messages , toolMessages )
164119 } else {
165120 if ( newResp . choices [ 0 ] . message . content ) {
166121 currentMessage . renderContent . push ( {
@@ -180,8 +135,7 @@ export const sendMcpRequest = async (messages: LLMMessage[], options: RequestOpt
180135 requestOptions = options
181136 messages . at ( - 1 ) ! . renderContent = [ { type : 'loading' , content : '' } ]
182137 const historyRaw = toRaw ( messages . slice ( 0 , - 1 ) ) as LLMMessage [ ]
183- const requestMessages = withSystemPromptOnce ( historyRaw )
184- const res = await fetchLLM ( formatMessages ( requestMessages ) , tools , options )
138+ const res = await fetchLLM ( formatMessages ( historyRaw ) , tools , options )
185139 delete messages . at ( - 1 ) ! . renderContent
186140 const hasToolCall = res . choices [ 0 ] . message . tool_calls ?. length > 0
187141 if ( hasToolCall ) {
0 commit comments