File tree Expand file tree Collapse file tree
app/service/agent/core/providers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -139,6 +139,9 @@ export function parseOpenAIStream(
139139 // 标记是否已通过 [DONE] 信号发出了 done 事件,避免 .then() 再次发出
140140 let doneSent = false ;
141141
142+ // 跨 chunk 追踪 <think>...</think> 块状态(用于把思考混在 content 里的模型)
143+ let inThinkBlock = false ;
144+
142145 return readSSEStream (
143146 reader ,
144147 signal ,
@@ -196,7 +199,43 @@ export function parseOpenAIStream(
196199 }
197200 }
198201 } else {
199- onEvent ( { type : "content_delta" , delta : delta . content } ) ;
202+ // 处理 <think>...</think> 内联标签(reasoning 模型)
203+ // 思考内容路由为 thinking_delta,避免裸露标签出现在对话里
204+ let remaining : string = delta . content ;
205+
206+ while ( remaining . length > 0 ) {
207+ if ( inThinkBlock ) {
208+ // 已在 think 块内,找结束标签
209+ const endIdx = remaining . indexOf ( "</think>" ) ;
210+ if ( endIdx === - 1 ) {
211+ // 整段都是思考内容
212+ onEvent ( { type : "thinking_delta" , delta : remaining } ) ;
213+ remaining = "" ;
214+ } else {
215+ // 结束标签之前是思考内容,之后是正文
216+ if ( endIdx > 0 ) {
217+ onEvent ( { type : "thinking_delta" , delta : remaining . slice ( 0 , endIdx ) } ) ;
218+ }
219+ inThinkBlock = false ;
220+ remaining = remaining . slice ( endIdx + "</think>" . length ) ;
221+ }
222+ } else {
223+ // 不在 think 块内,找开始标签
224+ const startIdx = remaining . indexOf ( "<think>" ) ;
225+ if ( startIdx === - 1 ) {
226+ // 整段都是正文
227+ onEvent ( { type : "content_delta" , delta : remaining } ) ;
228+ remaining = "" ;
229+ } else {
230+ // 开始标签之前是正文,之后进入思考块
231+ if ( startIdx > 0 ) {
232+ onEvent ( { type : "content_delta" , delta : remaining . slice ( 0 , startIdx ) } ) ;
233+ }
234+ inThinkBlock = true ;
235+ remaining = remaining . slice ( startIdx + "<think>" . length ) ;
236+ }
237+ }
238+ }
200239 }
201240 }
202241
Original file line number Diff line number Diff line change @@ -385,7 +385,9 @@ function AgentProvider() {
385385 body = JSON . stringify ( {
386386 model : editingModel . model || "claude-sonnet-4-20250514" ,
387387 max_tokens : 256 ,
388+ system : "Reply briefly. No thinking or reasoning." ,
388389 messages : [ { role : "user" , content : "hi" } ] ,
390+ stream : false ,
389391 } ) ;
390392 } else {
391393 chatUrl = `${ baseUrl } /chat/completions` ;
@@ -396,7 +398,11 @@ function AgentProvider() {
396398 body = JSON . stringify ( {
397399 model : editingModel . model || defaultModel ,
398400 max_tokens : 256 ,
399- messages : [ { role : "user" , content : "hi" } ] ,
401+ messages : [
402+ { role : "system" , content : "Reply briefly. No thinking or reasoning." } ,
403+ { role : "user" , content : "hi" } ,
404+ ] ,
405+ stream : false ,
400406 } ) ;
401407 }
402408
You can’t perform that action at this time.
0 commit comments