@@ -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' ;
@@ -62,6 +63,7 @@ export async function rateGeneratedCode(
6263 let categorizedFiles : CategorizedFiles | null = null ;
6364 let totalPoints = 0 ;
6465 let maxOverallPoints = 0 ;
66+ const ratingsContext : RatingsContext = { } ;
6567
6668 // Rating may also invoke LLMs. Track the usage.
6769 const tokenUsage = {
@@ -95,11 +97,16 @@ export async function rateGeneratedCode(
9597 serveTestingResult ,
9698 repairAttempts ,
9799 outputFiles . length ,
98- axeRepairAttempts
100+ axeRepairAttempts ,
101+ ratingsContext
99102 ) ;
100103 } else if ( current . kind === RatingKind . PER_FILE ) {
101104 categorizedFiles ??= splitFilesIntoCategories ( outputFiles ) ;
102- result = await runPerFileRating ( current , categorizedFiles ) ;
105+ result = await runPerFileRating (
106+ current ,
107+ categorizedFiles ,
108+ ratingsContext
109+ ) ;
103110 } else if ( current . kind === RatingKind . LLM_BASED ) {
104111 result = await runLlmBasedRating (
105112 environment ,
@@ -113,7 +120,8 @@ export async function rateGeneratedCode(
113120 repairAttempts ,
114121 axeRepairAttempts ,
115122 abortSignal ,
116- autoraterModel
123+ autoraterModel ,
124+ ratingsContext
117125 ) ;
118126 } else {
119127 throw new UserFacingError ( `Unsupported rating type ${ current } ` ) ;
@@ -139,6 +147,7 @@ export async function rateGeneratedCode(
139147 ) ;
140148 }
141149
150+ ratingsContext [ current . id ] = result ;
142151 category . assessments . push ( result ) ;
143152 }
144153
@@ -178,14 +187,16 @@ function runPerBuildRating(
178187 serveResult : ServeTestingResult | null ,
179188 repairAttempts : number ,
180189 generatedFileCount : number ,
181- axeRepairAttempts : number
190+ axeRepairAttempts : number ,
191+ ratingsContext : RatingsContext
182192) : IndividualAssessment | SkippedIndividualAssessment {
183193 const rateResult = rating . rate ( {
184194 buildResult,
185195 serveResult,
186196 repairAttempts,
187197 generatedFileCount,
188198 axeRepairAttempts,
199+ ratingsContext,
189200 } ) ;
190201
191202 // If the rating was skipped (e.g., Axe test wasn't run), create a skipped assessment.
@@ -203,7 +214,8 @@ function runPerBuildRating(
203214
204215async function runPerFileRating (
205216 rating : PerFileRating ,
206- categorizedFiles : CategorizedFiles
217+ categorizedFiles : CategorizedFiles ,
218+ ratingsContext : RatingsContext
207219) : Promise < IndividualAssessment | SkippedIndividualAssessment > {
208220 const errorMessages : string [ ] = [ ] ;
209221 let contentType : PerFileRatingContentType ;
@@ -234,7 +246,7 @@ async function runPerFileRating(
234246 // Remove comments from the code to avoid false-detection of bad patterns.
235247 // Some keywords like `NgModule` can be used in code comments.
236248 const code = removeComments ( file . code , contentType ) ;
237- const result = await rating . rate ( code , file . filePath ) ;
249+ const result = await rating . rate ( code , file . filePath , ratingsContext ) ;
238250 let coeff : number ;
239251
240252 if ( typeof result === 'number' ) {
@@ -279,7 +291,8 @@ async function runLlmBasedRating(
279291 repairAttempts : number ,
280292 axeRepairAttempts : number ,
281293 abortSignal : AbortSignal ,
282- autoraterModel : string
294+ autoraterModel : string ,
295+ ratingsContext : RatingsContext
283296) : Promise < IndividualAssessment | SkippedIndividualAssessment > {
284297 const result = await rating . rate ( {
285298 environment,
@@ -293,6 +306,7 @@ async function runLlmBasedRating(
293306 repairAttempts,
294307 axeRepairAttempts,
295308 abortSignal,
309+ ratingsContext,
296310 } ) ;
297311
298312 if ( result . state === RatingState . SKIPPED ) {
0 commit comments