@@ -10,24 +10,22 @@ function toPascalCase(kebabCase: string): string {
1010 * UI Registry that manages bundled UI HTML strings for tools.
1111 */
1212export class UIRegistry {
13- private customUIs : Map < string , string > = new Map ( ) ;
13+ private customUIs ?: ( toolName : string ) => string | null | Promise < string | null > ;
1414 private cache : Map < string , string > = new Map ( ) ;
1515
16- constructor ( options ?: { customUIs ?: Record < string , string > } ) {
17- if ( options ?. customUIs ) {
18- for ( const [ toolName , html ] of Object . entries ( options . customUIs ) ) {
19- this . customUIs . set ( toolName , html ) ;
20- }
21- }
16+ constructor ( options ?: { customUIs ?: ( toolName : string ) => string | null | Promise < string | null > } ) {
17+ this . customUIs = options ?. customUIs ;
2218 }
2319
2420 /**
2521 * Gets the UI HTML string for a tool, or null if none exists.
2622 */
2723 async get ( toolName : string ) : Promise < string | null > {
28- const customUI = this . customUIs . get ( toolName ) ;
29- if ( customUI !== undefined ) {
30- return customUI ;
24+ if ( this . customUIs ) {
25+ const customUI = await this . customUIs ( toolName ) ;
26+ if ( customUI !== null && customUI !== undefined ) {
27+ return customUI ;
28+ }
3129 }
3230
3331 const cached = this . cache . get ( toolName ) ;
@@ -38,7 +36,7 @@ export class UIRegistry {
3836 try {
3937 const module = ( await import ( `../lib/tools/${ toolName } .js` ) ) as Record < string , string > ;
4038 const exportName = `${ toPascalCase ( toolName ) } Html` ;
41- const html = module [ exportName ] ;
39+ const html = module [ exportName ] ; // HTML generated at build time
4240 if ( html === undefined ) {
4341 return null ;
4442 }
0 commit comments