@@ -61,9 +61,7 @@ export class ChatService {
6161 body : ChatRequestDto ,
6262 onSSEEvent ?: ( eventName : string , data : Record < string , unknown > ) => void ,
6363 ) : Promise < string > {
64- const { message, mode, agent : agentType , client_shell : clientShell , model : modelName } = body ;
65- const forceQA = message . trim ( ) . startsWith ( '/ask ' ) ;
66- const forceAgent = mode === 'agent' || message . trim ( ) . startsWith ( '/agent ' ) ;
64+ const { message, agent : agentType , client_shell : clientShell , model : modelName } = body ;
6765 const sessionId = ( body . session_id ?? '' ) . trim ( ) || this . defaultSessionId ;
6866 this . getOrCreateSession ( sessionId , agentType ) ;
6967 this . appendSessionMessage ( sessionId , MessageRole . USER , message ) ;
@@ -78,14 +76,11 @@ export class ChatService {
7876 try {
7977 return await this . _handleMessageCore ( {
8078 message,
81- mode,
8279 agentType,
8380 clientShell,
8481 modelName,
8582 sessionId,
8683 session,
87- forceQA,
88- forceAgent,
8984 emit,
9085 } ) ;
9186 } catch ( error ) {
@@ -98,27 +93,14 @@ export class ChatService {
9893
9994 private async _handleMessageCore ( params : {
10095 message : string ;
101- mode ?: string ;
10296 agentType ?: string ;
10397 clientShell ?: ChatRequestDto [ 'client_shell' ] ;
10498 modelName ?: string ;
10599 sessionId : string ;
106100 session : Session ;
107- forceQA : boolean ;
108- forceAgent : boolean ;
109101 emit : ( name : string , data : Record < string , unknown > ) => void ;
110102 } ) : Promise < string > {
111- const {
112- message,
113- agentType,
114- clientShell,
115- modelName,
116- sessionId,
117- session,
118- forceQA,
119- forceAgent,
120- emit,
121- } = params ;
103+ const { message, agentType, clientShell, modelName, sessionId, session, emit } = params ;
122104
123105 /** 1) 启发式 focus 即时更新(IP/CVE/域名/URL/协议词) */
124106 this . contextAssembler . updateFocusFromInput ( sessionId , message ) ;
@@ -193,7 +175,7 @@ export class ChatService {
193175
194176 /** 5) 组装最终上下文(按当前模型预算 + focus 加权 + pinned 优先级) */
195177 const selectedAgent = this . agents [ agentType ?? 'hackbot' ] ?? this . agents [ 'hackbot' ] ;
196- const effectiveModelName = modelName || ( selectedAgent as any ) . llm ?. model || undefined ;
178+ const effectiveModelName = modelName || resolveAgentModelName ( selectedAgent ) ;
197179 const context = await this . contextAssembler . build ( {
198180 query : message ,
199181 session,
@@ -408,7 +390,7 @@ export class ChatService {
408390 return {
409391 handled : true ,
410392 result : ( async ( ) => {
411- const qaModelName = modelName || ( this . qaAgent as any ) . llm ?. model || undefined ;
393+ const qaModelName = modelName || resolveAgentModelName ( this . qaAgent ) ;
412394 const ctx = await this . contextAssembler . build ( {
413395 query : message ,
414396 session,
@@ -498,3 +480,20 @@ export class ChatService {
498480 }
499481 }
500482}
483+
484+ function resolveAgentModelName ( agent : unknown ) : string | undefined {
485+ if ( ! agent || typeof agent !== 'object' || ! ( 'llm' in agent ) ) {
486+ return undefined ;
487+ }
488+
489+ try {
490+ const llm = ( agent as { llm ?: unknown } ) . llm ;
491+ if ( ! llm || typeof llm !== 'object' || ! ( 'model' in llm ) ) {
492+ return undefined ;
493+ }
494+ const model = ( llm as { model ?: unknown } ) . model ;
495+ return typeof model === 'string' && model . trim ( ) ? model : undefined ;
496+ } catch {
497+ return undefined ;
498+ }
499+ }
0 commit comments