@@ -22,7 +22,7 @@ export class ModifiedFilesTracker {
2222 private readonly props : ModifiedFilesTrackerProps ;
2323 private readonly collapsibleContent : CollapsibleContent ;
2424 public titleText : string = 'No files modified!' ;
25- private readonly allFiles : Map < string , { fileList : NonNullable < ChatItemContent [ 'fileList' ] > ; messageId : string } > = new Map ( ) ;
25+ private readonly allFiles : Map < string , { fileList : NonNullable < ChatItemContent [ 'fileList' ] > ; messageId : string ; chatItem : ChatItem } > = new Map ( ) ;
2626
2727 constructor ( props : ModifiedFilesTrackerProps ) {
2828 console . log ( '[ModifiedFilesTracker] Constructor called with props:' , {
@@ -65,9 +65,9 @@ export class ModifiedFilesTracker {
6565 if ( contentWrapper == null ) return ;
6666
6767 // Add files to the collection if provided
68- if ( fileList != null && ( fileList . filePaths ?. length ?? 0 ) > 0 ) {
68+ if ( fileList != null && ( fileList . filePaths ?. length ?? 0 ) > 0 && this . props . chatItem != null ) {
6969 const messageId = chatItemMessageId ?? `modified-files-tracker-${ this . props . tabId } ` ;
70- this . allFiles . set ( messageId , { fileList, messageId } ) ;
70+ this . allFiles . set ( messageId , { fileList, messageId, chatItem : this . props . chatItem } ) ;
7171 }
7272
7373 // Clear and re-render all files
@@ -89,7 +89,7 @@ export class ModifiedFilesTracker {
8989 }
9090
9191 private renderAllFilePills ( contentWrapper : Element ) : void {
92- this . allFiles . forEach ( ( { fileList, messageId } ) => {
92+ this . allFiles . forEach ( ( { fileList, messageId, chatItem } ) => {
9393 const { filePaths = [ ] , deletedFiles = [ ] , actions, details } = fileList ;
9494
9595 // Create a wrapper for each file group
@@ -134,12 +134,12 @@ export class ModifiedFilesTracker {
134134 horizontalContainer . appendChild ( fileTreeWrapper . render ) ;
135135
136136 // Add buttons for this specific file if they exist
137- if ( this . props . chatItem ?. header ?. buttons != null && Array . isArray ( this . props . chatItem . header ?. buttons ) && this . props . chatItem . header ?. buttons . length > 0 ) {
137+ if ( chatItem ?. header ?. buttons != null && Array . isArray ( chatItem . header ?. buttons ) && chatItem . header ?. buttons . length > 0 ) {
138138 const buttonsWrapper = new ChatItemButtonsWrapper ( {
139139 tabId : this . props . tabId ,
140140 classNames : [ 'mynah-modified-files-file-buttons' ] ,
141141 formItems : null ,
142- buttons : this . props . chatItem . header ?. buttons ,
142+ buttons : chatItem . header ?. buttons ,
143143 onActionClick : action => {
144144 MynahUIGlobalEvents . getInstance ( ) . dispatch ( MynahEventNames . BODY_ACTION_CLICKED , {
145145 tabId : this . props . tabId ,
@@ -215,6 +215,24 @@ export class ModifiedFilesTracker {
215215 }
216216 }
217217
218+ public updateChatItem ( updateWith : Partial < ChatItem > , messageId ?: string ) : void {
219+ if ( messageId != null ) {
220+ // Update specific chat item in allFiles
221+ const fileData = this . allFiles . get ( messageId ) ;
222+ if ( fileData != null ) {
223+ const updatedChatItem = { ...fileData . chatItem , ...updateWith } ;
224+ this . allFiles . set ( messageId , { ...fileData , chatItem : updatedChatItem } ) ;
225+
226+ // Re-render all files to reflect the update
227+ const contentWrapper = this . collapsibleContent . render . querySelector ( '.mynah-collapsible-content-label-content-wrapper' ) ;
228+ if ( contentWrapper != null ) {
229+ contentWrapper . innerHTML = '' ;
230+ this . renderAllFilePills ( contentWrapper ) ;
231+ }
232+ }
233+ }
234+ }
235+
218236 public clear ( ) : void {
219237 this . allFiles . clear ( ) ;
220238 this . titleText = 'No files modified!' ;
0 commit comments