@@ -32,7 +32,10 @@ import { WorkspaceProvider } from '@/context/providers/workspace/workspace-provi
3232import { natural_sort } from '@/utils/natural-sort'
3333import { t } from '@/i18n'
3434import { is_truncation_line } from './utils/edit-formats/truncations'
35- import { RelevantFileInPreview } from '@shared/types/file-in-preview'
35+ import {
36+ RelevantFileInPreview ,
37+ ItemInPreview
38+ } from '@shared/types/file-in-preview'
3639import { PreviewDecision } from './utils/preview/types'
3740import { set_response_preview_promise_resolve } from './utils/preview/preview'
3841
@@ -116,65 +119,88 @@ export const process_chat_response = async (params: {
116119 vscode . workspace . workspaceFolders ?. length == 1
117120
118121 if ( params . clipboard_items . some ( ( item ) => item . type == 'relevant-files' ) ) {
119- const relevant_files_item = params . clipboard_items . find (
120- ( item ) => item . type == 'relevant-files'
121- ) as RelevantFilesItem
122-
123122 const current_checked_files =
124123 params . workspace_provider . get_export_state ( ) . regular . checked_files
125124
126125 const workspace_roots = params . workspace_provider . get_workspace_roots ( )
127- const all_paths_to_process = new Set < string > ( relevant_files_item . file_paths )
128126
129127 const files_for_preview : RelevantFileInPreview [ ] = [ ]
128+ const items_for_preview : ItemInPreview [ ] = [ ]
130129
131- for ( const rel_path of Array . from ( all_paths_to_process ) ) {
132- let absolute_path : string | undefined
133- let matched_workspace_root : string | undefined
134- for ( const root of workspace_roots ) {
135- const potential = path . join ( root , rel_path )
136- if ( fs . existsSync ( potential ) ) {
137- absolute_path = potential
138- matched_workspace_root = root
139- break
140- }
141- }
130+ for ( const item of params . clipboard_items ) {
131+ if ( item . type == 'relevant-files' ) {
132+ const relevant_files_item = item as RelevantFilesItem
133+ const all_paths_to_process = new Set < string > (
134+ relevant_files_item . file_paths
135+ )
142136
143- if ( absolute_path && matched_workspace_root ) {
144- const count =
145- await params . workspace_provider . calculate_file_tokens ( absolute_path )
137+ const local_files : RelevantFileInPreview [ ] = [ ]
138+
139+ for ( const rel_path of Array . from ( all_paths_to_process ) ) {
140+ let absolute_path : string | undefined
141+ let matched_workspace_root : string | undefined
142+ for ( const root of workspace_roots ) {
143+ const potential = path . join ( root , rel_path )
144+ if ( fs . existsSync ( potential ) ) {
145+ absolute_path = potential
146+ matched_workspace_root = root
147+ break
148+ }
149+ }
146150
147- let workspace_name : string | undefined
148- if ( workspace_roots . length > 1 ) {
149- workspace_name = params . workspace_provider . get_workspace_name (
150- matched_workspace_root
151- )
152- }
151+ if ( absolute_path && matched_workspace_root ) {
152+ const count =
153+ await params . workspace_provider . calculate_file_tokens (
154+ absolute_path
155+ )
156+
157+ let workspace_name : string | undefined
158+ if ( workspace_roots . length > 1 ) {
159+ workspace_name = params . workspace_provider . get_workspace_name (
160+ matched_workspace_root
161+ )
162+ }
153163
154- let is_checked = true
155- if ( params . args ?. relevant_files ) {
156- const history_file = params . args . relevant_files . find (
157- ( f ) =>
158- f . file_path === rel_path && f . workspace_name === workspace_name
159- )
160- if ( history_file ) {
161- is_checked = history_file . is_checked
164+ let is_checked = true
165+ if ( params . args ?. relevant_files ) {
166+ const history_file = params . args . relevant_files . find (
167+ ( f ) =>
168+ f . file_path === rel_path &&
169+ f . workspace_name === workspace_name
170+ )
171+ if ( history_file ) {
172+ is_checked = history_file . is_checked
173+ }
174+ }
175+
176+ local_files . push ( {
177+ type : 'relevant-file' ,
178+ file_path : rel_path ,
179+ absolute_path : absolute_path ,
180+ workspace_name,
181+ is_checked,
182+ token_count : count . total
183+ } )
162184 }
163185 }
164186
165- files_for_preview . push ( {
166- type : 'relevant-file' ,
167- file_path : rel_path ,
168- absolute_path : absolute_path ,
169- workspace_name,
170- is_checked,
171- token_count : count . total
187+ local_files . sort ( ( a , b ) => natural_sort ( a . file_path , b . file_path ) )
188+ files_for_preview . push ( ...local_files )
189+ items_for_preview . push ( ...local_files )
190+ } else if ( item . type == 'text' ) {
191+ items_for_preview . push ( {
192+ type : 'text' ,
193+ content : item . content
194+ } )
195+ } else if ( item . type == 'inline-file' ) {
196+ items_for_preview . push ( {
197+ type : 'inline-file' ,
198+ content : item . content ,
199+ language : item . language
172200 } )
173201 }
174202 }
175203
176- files_for_preview . sort ( ( a , b ) => natural_sort ( a . file_path , b . file_path ) )
177-
178204 const created_at_for_preview = params . args ?. created_at ?? Date . now ( )
179205
180206 const history = params . panel_provider . response_history
@@ -207,7 +233,7 @@ export const process_chat_response = async (params: {
207233
208234 params . panel_provider . send_message ( {
209235 command : 'RESPONSE_PREVIEW_STARTED' ,
210- items : files_for_preview ,
236+ items : items_for_preview ,
211237 raw_instructions : params . args ?. raw_instructions ,
212238 created_at : created_at_for_preview ,
213239 url : params . args ?. url ,
0 commit comments