@@ -22,6 +22,8 @@ import (
2222 "go.uber.org/zap"
2323)
2424
25+ const reasoningContentPassbackSettingKey = "chat.reasoning_content_passback"
26+
2527// SendMessage 发送消息并调用上游渠道对话接口,支持多模态附件。
2628func (s * Service ) SendMessage (ctx context.Context , input SendMessageInput ) (result * SendMessageResult , retErr error ) {
2729 return s .sendMessageInternal (ctx , input , nil , false )
@@ -39,6 +41,14 @@ func (s *Service) StreamMessage(
3941 return s .sendMessageInternal (ctx , input , onDelta , true )
4042}
4143
44+ func (s * Service ) reasoningContentPassbackEnabled (ctx context.Context , userID uint , route * channel.ResolvedRoute ) bool {
45+ if route == nil || ! route .ReasoningContentPassback {
46+ return false
47+ }
48+ value , err := s .getUserSettingCached (ctx , userID , reasoningContentPassbackSettingKey )
49+ return err == nil && value != "false"
50+ }
51+
4252// emitEvent 统一处理可选事件回调,调用方无需重复判断 nil。
4353func emitEvent (onEvent func (string , map [string ]interface {}) error , eventType string , payload map [string ]interface {}) {
4454 if onEvent == nil {
@@ -385,6 +395,7 @@ func (s *Service) sendMessageInternal(
385395 return nil , err
386396 }
387397 resolvedRoute = route
398+ reasoningContentPassback := s .reasoningContentPassbackEnabled (ctx , input .UserID , route )
388399 if modelChanged || strings .TrimSpace (conversation .Model ) != strings .TrimSpace (route .PlatformModelName ) {
389400 conversation .Model = strings .TrimSpace (route .PlatformModelName )
390401 conversation .Provider = inferProvider (conversation .Model )
@@ -456,7 +467,7 @@ func (s *Service) sendMessageInternal(
456467 prefetch := <- prefetchCh
457468 contextMessages = s .expandContextMessagesToSnapshotBoundary (ctx , input .ConversationID , userMessage .ID , contextMessages , prefetch .snapshot , compactPolicy )
458469 promptScope := buildPromptScope (contextMessages , prefetch .snapshot , compactPolicy )
459- promptMessages := s .applyContextTokenBudget (promptScope .activeMessages (), route .UpstreamModel , route .ModelCapabilitiesJSON )
470+ promptMessages := s .applyContextTokenBudget (promptScope .activeMessages (), route .UpstreamModel , route .ModelCapabilitiesJSON , reasoningContentPassback )
460471 ragQuery := buildRAGQuery (promptMessages , input .Content , cfg .RAGQueryHistoryTurns )
461472
462473 conversationFileIDs := collectConversationFileIDs (promptMessages , input .FileIDs )
@@ -476,7 +487,9 @@ func (s *Service) sendMessageInternal(
476487 fileContextPlan := buildConversationFileContextPlan (conversationAttachments , fileMode , cfg , route .UpstreamModel , route .ModelCapabilitiesJSON , capability .RAGAvailable )
477488
478489 // 构建历史消息序列(不含系统注入)
479- historyMsgs := historyMessagesFromDomain (promptMessages )
490+ historyMsgs := historyMessagesFromDomain (promptMessages , historyMessageOptions {
491+ ReasoningContentPassback : reasoningContentPassback ,
492+ })
480493 if len (historyMsgs ) == 0 {
481494 historyMsgs = append (historyMsgs , llm.Message {
482495 Role : "user" ,
@@ -1102,7 +1115,7 @@ func (s *Service) sendMessageInternal(
11021115 break
11031116 }
11041117 reasoningContent := ""
1105- if route . ReasoningContentPassback {
1118+ if reasoningContentPassback {
11061119 reasoningContent = outputReasoningContent (upstreamOutput )
11071120 }
11081121 llmMessages = append (llmMessages ,
@@ -1206,6 +1219,10 @@ func (s *Service) sendMessageInternal(
12061219 retErr = err
12071220 return nil , err
12081221 }
1222+ assistantReasoningContent := ""
1223+ if reasoningContentPassback {
1224+ assistantReasoningContent = outputReasoningContent (upstreamOutput )
1225+ }
12091226 statefulPromptFingerprint := buildPromptStateFingerprint (promptStateFingerprintInput {
12101227 Protocol : route .Protocol ,
12111228 Endpoint : routeConfig .Endpoint ,
@@ -1214,7 +1231,7 @@ func (s *Service) sendMessageInternal(
12141231 PlatformModelName : conversation .Model ,
12151232 ContextConfig : statefulContextConfig ,
12161233 ContextState : statefulContextState ,
1217- Messages : buildNextStatefulPrefixMessages (fullLLMMessages , input .Content , assistantText ),
1234+ Messages : buildNextStatefulPrefixMessages (fullLLMMessages , input .Content , assistantText , assistantReasoningContent ),
12181235 Tools : toolRuntime .definitions ,
12191236 Options : filteredOptions ,
12201237 })
@@ -1267,6 +1284,7 @@ func (s *Service) sendMessageInternal(
12671284 UserMessage : userMessage ,
12681285 AssistantMessage : assistantMessage ,
12691286 AssistantText : assistantText ,
1287+ AssistantReasoningContent : assistantReasoningContent ,
12701288 InputTokens : effectiveInputTokens ,
12711289 CacheReadTokens : totalUsage .CacheReadTokens ,
12721290 CacheWriteTokens : totalUsage .CacheWriteTokens ,
0 commit comments