@@ -17,6 +17,7 @@ function formatElapsedTime() {
1717}
1818
1919/* clang-format off */
20+ /** @type {import('./types').YargsInput } */
2021const yargsObject = yargs
2122 . option ( 'example-urls' , {
2223 string : true ,
@@ -42,6 +43,7 @@ const OUTPUT_DIR = path.resolve(__dirname, 'data');
4243const { exampleUrls, label} = yargsObject ;
4344
4445class Logger {
46+ /** @type {import('./types').Logs } */
4547 #logs = { } ;
4648 #updateElapsedTimeInterval = 0 ;
4749 constructor ( ) {
@@ -72,6 +74,11 @@ class Logger {
7274 this . log ( 'head' , - 1 , `${ text } \n` ) ;
7375 }
7476
77+ /**
78+ * @param {string } id
79+ * @param {number } index
80+ * @param {string } text
81+ */
7582 log ( id , index , text ) {
7683 this . #updateElapsedTime( ) ;
7784 this . #logs[ id ] = { index, text} ;
@@ -259,6 +266,10 @@ class Example {
259266 } ) ;
260267
261268 const results = [ ] ;
269+
270+ /**
271+ * @returns {Promise<import('./types').ExecutedExample> }
272+ */
262273 const prompt = async query => {
263274 await this . #devtoolsPage. locator ( 'aria/Ask a question about the selected element' ) . click ( ) ;
264275
@@ -291,11 +302,12 @@ class Example {
291302 await done ;
292303 abort . abort ( ) ;
293304
294- const result = JSON . parse ( await this . #devtoolsPage. evaluate ( ( ) => {
305+ /** @type {import('./types').IndividualPromptRequestResponse[] } */
306+ const results = JSON . parse ( await this . #devtoolsPage. evaluate ( ( ) => {
295307 return localStorage . getItem ( 'freestylerStructuredLog' ) ;
296308 } ) ) ;
297309
298- return result . map ( r => ( { ...r , exampleId : this . id ( ) } ) ) ;
310+ return results . map ( r => ( { ...r , exampleId : this . id ( ) } ) ) ;
299311 } ;
300312
301313 for ( const query of this . #queries) {
@@ -307,6 +319,8 @@ class Example {
307319 await this . #page. close ( ) ;
308320 const elapsedTime = numberFormatter . format ( ( performance . now ( ) - executionStartTime ) / 1000 ) ;
309321 this . log ( `Finished (${ elapsedTime } s)` ) ;
322+
323+ /** @type {import('./types').ExecutedExample } */
310324 return { results, metadata : { exampleId : this . id ( ) , explanation : this . #explanation} } ;
311325 }
312326
@@ -326,6 +340,11 @@ class Example {
326340}
327341
328342const logger = new Logger ( ) ;
343+
344+ /**
345+ * @param {Example[] } examples
346+ * @return {Promise<RunResult> }
347+ */
329348async function runInParallel ( examples ) {
330349 logger . head ( 'Preparing examples...' ) ;
331350 for ( const example of examples ) {
@@ -348,8 +367,15 @@ async function runInParallel(examples) {
348367 return { allExampleResults, metadata} ;
349368}
350369
370+ /**
371+ * @param {Example[] } examples
372+ * @return {Promise<import('./types').RunResult> }
373+ */
351374async function runSequentially ( examples ) {
375+ /** @type {import('./types').ExecutedExample[] } */
352376 const allExampleResults = [ ] ;
377+
378+ /** @type {import('./types').ExampleMetadata } */
353379 const metadata = [ ] ;
354380 logger . head ( 'Running examples sequentially...' ) ;
355381 for ( const example of examples ) {
@@ -401,8 +427,11 @@ async function main() {
401427
402428 logger . head ( 'Preparing examples...' ) ;
403429 const examples = exampleUrls . map ( exampleUrl => new Example ( exampleUrl , browser ) ) ;
430+ /** @type {import('./types').IndividualPromptRequestResponse[] } */
404431 let allExampleResults = [ ] ;
432+ /** @type {import('./types').ExampleMetadata[] } */
405433 let metadata = [ ] ;
434+
406435 if ( yargsObject . parallel ) {
407436 ( { allExampleResults, metadata} = await runInParallel ( examples ) ) ;
408437 } else {
0 commit comments