11import * as vscode from 'vscode'
22import axios from 'axios'
3- import { FileItem } from '../utils/clipboard-parser'
3+ import {
4+ FileItem ,
5+ DiffItem ,
6+ parse_response
7+ } from '../utils/clipboard-parser/clipboard-parser'
48import { sanitize_file_name , create_safe_path } from '@/utils/path-sanitizer'
59import { Logger } from '@shared/utils/logger'
610import { OriginalFileState } from '@/commands/apply-chat-response-command/types/original-file-state'
711import { ToolConfig } from '@/services/model-providers-manager'
812import { PanelProvider } from '@/views/panel/backend/panel-provider'
913import { dictionary } from '@shared/constants/dictionary'
1014import { process_file } from '@/utils/intelligent-update-utils'
11- import { parse_multiple_files } from '../utils/clipboard-parser/parsers'
1215
1316export const handle_active_editor_intelligent_update = async ( params : {
1417 endpoint_url : string
@@ -44,13 +47,14 @@ export const handle_active_editor_intelligent_update = async (params: {
4447 message : 'Processing single file update'
4548 } )
4649
47- const raw_items = parse_multiple_files ( {
50+ const raw_items = parse_response ( {
4851 response : params . chat_response ,
4952 is_single_root_folder_workspace : params . is_single_root_folder_workspace
5053 } )
5154
5255 const files = raw_items . filter (
53- ( item ) : item is FileItem => item . type == 'file'
56+ ( item ) : item is FileItem | DiffItem =>
57+ item . type == 'file' || item . type == 'diff'
5458 )
5559
5660 if ( files . length == 0 ) {
@@ -67,22 +71,27 @@ export const handle_active_editor_intelligent_update = async (params: {
6771 // We only handle the first file as this handler is intended for single-file fallback
6872 const file_item = files [ 0 ]
6973
74+ let target_file_path = file_item . file_path
75+ if ( file_item . type == 'diff' && file_item . new_file_path ) {
76+ target_file_path = file_item . new_file_path
77+ }
78+
7079 let workspace_root = default_workspace_path
7180 if ( file_item . workspace_name && workspace_map . has ( file_item . workspace_name ) ) {
7281 workspace_root = workspace_map . get ( file_item . workspace_name ) !
7382 }
7483
75- const sanitized_path = sanitize_file_name ( file_item . file_path )
84+ const sanitized_path = sanitize_file_name ( target_file_path )
7685 const safe_path = create_safe_path ( workspace_root , sanitized_path )
7786
7887 if ( ! safe_path ) {
7988 vscode . window . showErrorMessage (
80- dictionary . error_message . INVALID_FILE_PATH_TRAVERSAL ( file_item . file_path )
89+ dictionary . error_message . INVALID_FILE_PATH_TRAVERSAL ( target_file_path )
8190 )
8291 Logger . error ( {
8392 function_name : 'handle_active_editor_intelligent_update' ,
8493 message : 'Invalid file path' ,
85- data : file_item . file_path
94+ data : target_file_path
8695 } )
8796 return null
8897 }
@@ -110,7 +119,7 @@ export const handle_active_editor_intelligent_update = async (params: {
110119 model : params . config . model ,
111120 temperature : params . config . temperature ,
112121 reasoning_effort : params . config . reasoning_effort ,
113- file_path : file_item . file_path ,
122+ file_path : target_file_path ,
114123 file_content : original_content ,
115124 instruction : file_item . content ,
116125 cancel_token : cancel_token_source . token ,
@@ -172,7 +181,7 @@ export const handle_active_editor_intelligent_update = async (params: {
172181
173182 return [
174183 {
175- file_path : file_item . file_path ,
184+ file_path : target_file_path ,
176185 content : original_content ,
177186 workspace_name : file_item . workspace_name
178187 }
0 commit comments