@@ -662,36 +662,48 @@ export function loadPromptFolder(
662
662
) : void {
663
663
const promptsPath = resolve ( dir ) ;
664
664
if ( existsSync ( promptsPath ) ) {
665
- const dirEnts = readdirSync ( promptsPath , {
666
- withFileTypes : true ,
667
- recursive : true ,
668
- } ) ;
669
- for ( const dirEnt of dirEnts ) {
670
- const parentPath = dirEnt . parentPath ?? dirEnt . path ;
671
- if ( dirEnt . isFile ( ) && dirEnt . name . endsWith ( '.prompt' ) ) {
672
- if ( dirEnt . name . startsWith ( '_' ) ) {
673
- const partialName = dirEnt . name . substring ( 1 , dirEnt . name . length - 7 ) ;
674
- definePartial (
675
- registry ,
676
- partialName ,
677
- readFileSync ( join ( parentPath , dirEnt . name ) , {
678
- encoding : 'utf8' ,
679
- } )
680
- ) ;
681
- logger . debug (
682
- `Registered Dotprompt partial "${ partialName } " from "${ join ( parentPath , dirEnt . name ) } "`
683
- ) ;
684
- } else {
685
- // If this prompt is in a subdirectory, we need to include that
686
- // in the namespace to prevent naming conflicts.
687
- let prefix = '' ;
688
- let name = dirEnt . name ;
689
- if ( promptsPath !== parentPath ) {
690
- prefix = parentPath . replace ( `${ promptsPath } /` , '' ) + '/' ;
691
- }
692
- loadPrompt ( registry , promptsPath , name , prefix , ns ) ;
693
- }
665
+ loadPromptFolderRecursively ( registry , dir , ns , '' ) ;
666
+ }
667
+ }
668
+ export function loadPromptFolderRecursively (
669
+ registry : Registry ,
670
+ dir : string ,
671
+ ns : string ,
672
+ subDir : string
673
+ ) : void {
674
+ const promptsPath = resolve ( dir ) ;
675
+ const dirEnts = readdirSync ( join ( promptsPath , subDir ) , {
676
+ withFileTypes : true ,
677
+ } ) ;
678
+ for ( const dirEnt of dirEnts ) {
679
+ const parentPath = join ( promptsPath , subDir ) ;
680
+ let fileName = dirEnt . name ;
681
+ if ( dirEnt . isFile ( ) && fileName . endsWith ( '.prompt' ) ) {
682
+ if ( fileName . startsWith ( '_' ) ) {
683
+ const partialName = fileName . substring ( 1 , fileName . length - 7 ) ;
684
+ definePartial (
685
+ registry ,
686
+ partialName ,
687
+ readFileSync ( join ( parentPath , fileName ) , {
688
+ encoding : 'utf8' ,
689
+ } )
690
+ ) ;
691
+ logger . debug (
692
+ `Registered Dotprompt partial "${ partialName } " from "${ join ( parentPath , fileName ) } "`
693
+ ) ;
694
+ } else {
695
+ // If this prompt is in a subdirectory, we need to include that
696
+ // in the namespace to prevent naming conflicts.
697
+ loadPrompt (
698
+ registry ,
699
+ promptsPath ,
700
+ fileName ,
701
+ subDir ? `${ subDir } /` : '' ,
702
+ ns
703
+ ) ;
694
704
}
705
+ } else if ( dirEnt . isDirectory ( ) ) {
706
+ loadPromptFolderRecursively ( registry , dir , ns , join ( subDir , fileName ) ) ;
695
707
}
696
708
}
697
709
}
@@ -726,7 +738,7 @@ function loadPrompt(
726
738
name = parts [ 0 ] ;
727
739
variant = parts [ 1 ] ;
728
740
}
729
- const source = readFileSync ( join ( path , ( prefix ?? '' ) + filename ) , 'utf8' ) ;
741
+ const source = readFileSync ( join ( path , prefix ?? '' , filename ) , 'utf8' ) ;
730
742
const parsedPrompt = registry . dotprompt . parse ( source ) ;
731
743
definePromptAsync (
732
744
registry ,
0 commit comments