@@ -20,6 +20,7 @@ import {
2020 POINTS_FOR_CATEGORIES ,
2121 Rating ,
2222 CATEGORY_NAMES ,
23+ RatingsContext ,
2324} from './rating-types.js' ;
2425import { extractEmbeddedCodeFromTypeScript } from './embedded-languages.js' ;
2526import { Environment } from '../configuration/environment.js' ;
@@ -60,6 +61,7 @@ export async function rateGeneratedCode(
6061 let categorizedFiles : CategorizedFiles | null = null ;
6162 let totalPoints = 0 ;
6263 let maxOverallPoints = 0 ;
64+ const ratingsContext : RatingsContext = { } ;
6365
6466 // Rating may also invoke LLMs. Track the usage.
6567 const tokenUsage = {
@@ -92,11 +94,16 @@ export async function rateGeneratedCode(
9294 buildResult ,
9395 repairAttempts ,
9496 outputFiles . length ,
95- axeRepairAttempts
97+ axeRepairAttempts ,
98+ ratingsContext
9699 ) ;
97100 } else if ( current . kind === RatingKind . PER_FILE ) {
98101 categorizedFiles ??= splitFilesIntoCategories ( outputFiles ) ;
99- result = await runPerFileRating ( current , categorizedFiles ) ;
102+ result = await runPerFileRating (
103+ current ,
104+ categorizedFiles ,
105+ ratingsContext
106+ ) ;
100107 } else if ( current . kind === RatingKind . LLM_BASED ) {
101108 result = await runLlmBasedRating (
102109 environment ,
@@ -109,7 +116,8 @@ export async function rateGeneratedCode(
109116 repairAttempts ,
110117 axeRepairAttempts ,
111118 abortSignal ,
112- autoraterModel
119+ autoraterModel ,
120+ ratingsContext
113121 ) ;
114122 } else {
115123 throw new UserFacingError ( `Unsupported rating type ${ current } ` ) ;
@@ -135,6 +143,7 @@ export async function rateGeneratedCode(
135143 ) ;
136144 }
137145
146+ ratingsContext [ current . id ] = result ;
138147 category . assessments . push ( result ) ;
139148 }
140149
@@ -173,13 +182,15 @@ function runPerBuildRating(
173182 buildResult : BuildResult ,
174183 repairAttempts : number ,
175184 generatedFileCount : number ,
176- axeRepairAttempts : number
185+ axeRepairAttempts : number ,
186+ ratingsContext : RatingsContext
177187) : IndividualAssessment | SkippedIndividualAssessment {
178188 const rateResult = rating . rate ( {
179189 buildResult,
180190 repairAttempts,
181191 generatedFileCount,
182192 axeRepairAttempts,
193+ ratingsContext,
183194 } ) ;
184195
185196 // If the rating was skipped (e.g., Axe test wasn't run), create a skipped assessment.
@@ -197,7 +208,8 @@ function runPerBuildRating(
197208
198209async function runPerFileRating (
199210 rating : PerFileRating ,
200- categorizedFiles : CategorizedFiles
211+ categorizedFiles : CategorizedFiles ,
212+ ratingsContext : RatingsContext
201213) : Promise < IndividualAssessment | SkippedIndividualAssessment > {
202214 const errorMessages : string [ ] = [ ] ;
203215 let contentType : PerFileRatingContentType ;
@@ -228,7 +240,7 @@ async function runPerFileRating(
228240 // Remove comments from the code to avoid false-detection of bad patterns.
229241 // Some keywords like `NgModule` can be used in code comments.
230242 const code = removeComments ( file . code , contentType ) ;
231- const result = await rating . rate ( code , file . filePath ) ;
243+ const result = await rating . rate ( code , file . filePath , ratingsContext ) ;
232244 let coeff : number ;
233245
234246 if ( typeof result === 'number' ) {
@@ -272,7 +284,8 @@ async function runLlmBasedRating(
272284 repairAttempts : number ,
273285 axeRepairAttempts : number ,
274286 abortSignal : AbortSignal ,
275- autoraterModel : string
287+ autoraterModel : string ,
288+ ratingsContext : RatingsContext
276289) : Promise < IndividualAssessment | SkippedIndividualAssessment > {
277290 const result = await rating . rate ( {
278291 environment,
@@ -285,6 +298,7 @@ async function runLlmBasedRating(
285298 repairAttempts,
286299 axeRepairAttempts,
287300 abortSignal,
301+ ratingsContext,
288302 } ) ;
289303
290304 if ( result . state === RatingState . SKIPPED ) {
0 commit comments