@@ -392,33 +392,36 @@ export const BladeInterface: React.FC<BladeInterfaceProps> = ({
392392 try {
393393 const messages = await SessionService . loadSession ( sessionId ) ;
394394
395- const sessionMessages = messages . map ( ( msg , index ) => {
396- // 提取消息内容:如果是 ContentPart[] 数组,只提取文本部分
397- let content : string ;
398- if ( typeof msg . content === 'string' ) {
399- content = msg . content ;
400- } else if ( Array . isArray ( msg . content ) ) {
401- // 从 ContentPart[] 中提取文本
402- content = msg . content
403- . filter ( ( part ) : part is { type : 'text' ; text : string } => part . type === 'text' )
404- . map ( ( part ) => part . text )
405- . join ( '' ) ;
406- } else {
407- // 其他情况(不应该发生)
408- content = '' ;
409- }
395+ // 过滤并转换消息:只保留用户和助手的消息,过滤掉 tool 和 system 消息
396+ const sessionMessages = messages
397+ . filter ( ( msg ) => msg . role === 'user' || msg . role === 'assistant' )
398+ . map ( ( msg , index ) => {
399+ // 提取消息内容:如果是 ContentPart[] 数组,只提取文本部分
400+ let content : string ;
401+ if ( typeof msg . content === 'string' ) {
402+ content = msg . content ;
403+ } else if ( Array . isArray ( msg . content ) ) {
404+ // 从 ContentPart[] 中提取文本
405+ content = msg . content
406+ . filter ( ( part ) : part is { type : 'text' ; text : string } => part . type === 'text' )
407+ . map ( ( part ) => part . text )
408+ . join ( '' ) ;
409+ } else {
410+ // 其他情况(不应该发生)
411+ content = '' ;
412+ }
410413
411- return {
412- id : `restored-${ Date . now ( ) } -${ index } ` ,
413- role : msg . role ,
414- content,
415- timestamp : Date . now ( ) - ( messages . length - index ) * 1000 ,
416- metadata :
417- msg . metadata && typeof msg . metadata === 'object'
418- ? ( msg . metadata as Record < string , unknown > )
419- : undefined ,
420- } ;
421- } ) ;
414+ return {
415+ id : `restored-${ Date . now ( ) } -${ index } ` ,
416+ role : msg . role ,
417+ content,
418+ timestamp : Date . now ( ) - ( messages . length - index ) * 1000 ,
419+ metadata :
420+ msg . metadata && typeof msg . metadata === 'object'
421+ ? ( msg . metadata as Record < string , unknown > )
422+ : undefined ,
423+ } ;
424+ } ) ;
422425
423426 sessionActions . restoreSession ( sessionId , sessionMessages ) ;
424427 appActions . closeModal ( ) ;
0 commit comments