@@ -13,7 +13,7 @@ import {UserFacingError} from '../utils/errors.js';
1313import { generateId } from '../utils/id-generation.js' ;
1414import { lazy } from '../utils/lazy-creation.js' ;
1515import { EnvironmentConfig } from './environment-config.js' ;
16- import { MultiStepPrompt } from './multi-step-prompt .js' ;
16+ import { EvalPromptWithMetadata , MultiStepPrompt } from './prompts .js' ;
1717import { renderPromptTemplate } from './prompt-templating.js' ;
1818
1919/** Represents a single prompt evaluation environment. */
@@ -176,6 +176,18 @@ export class Environment {
176176 for ( const def of prompts ) {
177177 if ( def instanceof MultiStepPrompt ) {
178178 result . push ( this . getMultiStepPrompt ( def , envRatings ) ) ;
179+ } else if ( def instanceof EvalPromptWithMetadata ) {
180+ result . push (
181+ Promise . resolve ( {
182+ name : def . name ,
183+ kind : 'single' ,
184+ prompt : def . text ,
185+ ratings : [ ...envRatings , ...( def . opts . extraRatings ?? [ ] ) ] ,
186+ systemPromptType : 'generation' ,
187+ contextFilePatterns : def . opts . contextFilePatterns ?? [ ] ,
188+ metadata : def . opts . metadata ,
189+ } satisfies PromptDefinition ) ,
190+ ) ;
179191 } else {
180192 let path : string ;
181193 let ratings : Rating [ ] ;
@@ -198,6 +210,7 @@ export class Environment {
198210 relativePath ,
199211 ratings ,
200212 /* isEditing */ false ,
213+ undefined ,
201214 ) ,
202215 ) ,
203216 ) ;
@@ -216,12 +229,13 @@ export class Environment {
216229 * @param ratings Ratings to run against the definition.
217230 * @param isEditing Whether this is an editing or generation step.
218231 */
219- private async getStepPromptDefinition (
232+ private async getStepPromptDefinition < Metadata > (
220233 name : string ,
221234 relativePath : string ,
222235 ratings : Rating [ ] ,
223236 isEditing : boolean ,
224- ) : Promise < PromptDefinition > {
237+ metadata : Metadata ,
238+ ) : Promise < PromptDefinition < Metadata > > {
225239 const { result, contextFiles} = await this . renderEnvironmentPrompt ( relativePath ) ;
226240
227241 return {
@@ -231,7 +245,8 @@ export class Environment {
231245 ratings,
232246 systemPromptType : isEditing ? 'editing' : 'generation' ,
233247 contextFilePatterns : contextFiles ,
234- } satisfies PromptDefinition ;
248+ metadata,
249+ } satisfies PromptDefinition < Metadata > ;
235250 }
236251
237252 /**
@@ -284,6 +299,7 @@ export class Environment {
284299 ratings . unshift ( ...def . stepRatings [ current . name ] ) ;
285300 }
286301
302+ const stepMetadata = def . stepMetadata [ current . name ] ;
287303 const stepNum = parseInt ( match [ 1 ] ) ;
288304 if ( stepNum === 0 ) {
289305 throw new UserFacingError ( 'Multi-step prompts start with `step-1`.' ) ;
@@ -293,6 +309,7 @@ export class Environment {
293309 join ( def . directoryPath , current . name ) ,
294310 ratings ,
295311 /*isEditing */ stepNum !== 1 ,
312+ stepMetadata ,
296313 ) ;
297314
298315 stepValues [ step . name ] = stepNum ;
0 commit comments