11import {
2- CONVERTS_DIR_NAME ,
32 FILES_NOT_FOUND_ERROR_CODE ,
43 GENAI_ANY_REGEX ,
5- GENAI_ANYTS_REGEX ,
64 HTTPS_REGEX ,
75 JSON5_REGEX ,
86 TRACE_FILENAME ,
@@ -30,6 +28,8 @@ import { toSignal } from "../../core/src/cancellation"
3028import { normalizeInt } from "../../core/src/cleaners"
3129import { YAMLStringify } from "../../core/src/yaml"
3230import { ensureDotGenaiscriptPath , getConvertDir } from "../../core/src/workdir"
31+ import { GenerationStats } from "../../core/src/usage"
32+ import { measure } from "../../core/src/performance"
3333
3434export async function convertFiles (
3535 scriptId : string ,
@@ -134,6 +134,7 @@ export async function convertFiles(
134134 ( filename ) => ( { filename } ) as WorkspaceFile
135135 )
136136
137+ const usage = new GenerationStats ( "" )
137138 const results : Record < string , string > = { }
138139 const p = new PLimitPromiseQueue ( normalizeInt ( concurrency ) || 1 )
139140 await p . mapAll ( files , async ( file ) => {
@@ -147,6 +148,7 @@ export async function convertFiles(
147148 const fileTrace = convertTrace . startTraceDetails ( file . filename )
148149 convertTrace . item ( link ( "trace" , fileOutTrace ) )
149150 logVerbose ( `trace: ${ fileOutTrace } ` )
151+ const m = measure ( "convert" )
150152 try {
151153 // apply AI transformation
152154 const result = await run ( script . filename , file . filename , {
@@ -228,6 +230,8 @@ export async function convertFiles(
228230 }
229231
230232 results [ file . filename ] = text
233+ const end = m ( )
234+ usage . addUsage ( result . stats , end )
231235 } catch ( error ) {
232236 logError ( error )
233237 fileTrace . error ( undefined , error )
@@ -237,5 +241,6 @@ export async function convertFiles(
237241 }
238242 } )
239243
244+ usage . log ( )
240245 logVerbose ( `trace: ${ outTraceFilename } ` )
241246}
0 commit comments