11import path from 'path'
22import { createModelProvider } from '@/ai/helpers'
3+ import { AbortError } from '@/constants'
34import { traverseFileOrFolders } from '@/file-utils/traverse-fs'
4- import { getCurrentWorkspaceFolderEditor } from '@/utils'
5+ import { getCurrentWorkspaceFolderEditor , toPlatformPath } from '@/utils'
56import { z } from 'zod'
67
78export interface PreProcessInfo {
@@ -16,10 +17,12 @@ export interface PreProcessInfo {
1617
1718export const getPreProcessInfo = async ( {
1819 prompt,
19- fileRelativePathsForProcess
20+ fileRelativePathsForProcess,
21+ abortController
2022} : {
2123 prompt : string
2224 fileRelativePathsForProcess : string [ ]
25+ abortController ?: AbortController
2326} ) : Promise <
2427 PreProcessInfo & {
2528 allFileRelativePaths : string [ ]
@@ -38,6 +41,7 @@ export const getPreProcessInfo = async ({
3841
3942 const modelProvider = await createModelProvider ( )
4043 const aiRunnable = await modelProvider . createStructuredOutputRunnable ( {
44+ signal : abortController ?. signal ,
4145 useHistory : false ,
4246 zodSchema : z . object ( {
4347 processFilePathInfo : z
@@ -115,33 +119,58 @@ Please analyze these files and provide the requested information to help streaml
115119 `
116120 } )
117121
122+ if ( abortController ?. signal . aborted ) throw AbortError
123+
124+ aiRes . dependenceFileRelativePath = toPlatformPath (
125+ aiRes . dependenceFileRelativePath || ''
126+ )
127+ aiRes . ignoreFileRelativePaths =
128+ aiRes . ignoreFileRelativePaths ?. map ( toPlatformPath )
129+ aiRes . processFilePathInfo = aiRes . processFilePathInfo . map ( info => ( {
130+ sourceFileRelativePath : toPlatformPath ( info . sourceFileRelativePath ) ,
131+ processedFileRelativePath : toPlatformPath ( info . processedFileRelativePath ) ,
132+ referenceFileRelativePaths :
133+ info . referenceFileRelativePaths . map ( toPlatformPath )
134+ } ) )
135+
118136 // data cleaning
119137 // Process and filter the file path information
120138 const finalProcessFilePathInfo : PreProcessInfo [ 'processFilePathInfo' ] =
121139 aiRes . processFilePathInfo
122140 . map ( info => {
141+ const {
142+ sourceFileRelativePath,
143+ processedFileRelativePath,
144+ referenceFileRelativePaths
145+ } = info
146+ const { ignoreFileRelativePaths } = aiRes
147+
123148 // Extract the base name and extension from the source file path
124149 const sourceBaseName = path . basename (
125- info . sourceFileRelativePath ,
126- path . extname ( info . sourceFileRelativePath )
150+ sourceFileRelativePath ,
151+ path . extname ( sourceFileRelativePath )
127152 )
128153 // Get the extension from the processed file path
129- const processedExtName = path . extname ( info . processedFileRelativePath )
154+ const processedExtName = path . extname ( processedFileRelativePath )
130155 // Construct the full processed file path
131156 const fullProcessedPath = path . join (
132- path . dirname ( info . sourceFileRelativePath ) ,
157+ path . dirname ( sourceFileRelativePath ) ,
133158 sourceBaseName + processedExtName
134159 )
135160
136161 // Check if the processed file path should be ignored
137162 const shouldIgnore =
138- fullProcessedPath === info . sourceFileRelativePath &&
139- aiRes . ignoreFileRelativePaths ?. includes ( info . sourceFileRelativePath )
163+ fullProcessedPath === sourceFileRelativePath &&
164+ ignoreFileRelativePaths ?. includes ( sourceFileRelativePath )
140165
141166 // Return the new info object or null if it should be ignored
142167 return shouldIgnore
143168 ? null
144- : { ...info , processedFileRelativePath : fullProcessedPath }
169+ : {
170+ sourceFileRelativePath,
171+ processedFileRelativePath : toPlatformPath ( fullProcessedPath ) ,
172+ referenceFileRelativePaths
173+ }
145174 } )
146175 // Filter out any null entries
147176 . filter (
0 commit comments