@@ -2,6 +2,7 @@ import { BaseTool } from "../tools/BaseTool.js";
22import { fileURLToPath } from "url" ;
33import { dirname , join } from "path" ;
44import { promises as fs } from "fs" ;
5+ import { cwd } from "process" ;
56
67export interface ToolLoaderOptions {
78 toolsDir ?: string ;
@@ -18,9 +19,8 @@ export class ToolLoader {
1819 }
1920
2021 private findDefaultToolsDir ( ) : string {
21- const currentFilePath = fileURLToPath ( import . meta. url ) ;
22- const currentDir = dirname ( currentFilePath ) ;
23- return join ( currentDir , ".." , ".." , "dist" , "tools" ) ;
22+ // Use current working directory + dist/tools as default
23+ return join ( cwd ( ) , "dist" , "tools" ) ;
2424 }
2525
2626 private isToolFile ( file : string ) : boolean {
@@ -45,30 +45,45 @@ export class ToolLoader {
4545
4646 async loadTools ( ) : Promise < BaseTool [ ] > {
4747 try {
48+ console . log ( `Loading tools from directory: ${ this . toolsDir } ` ) ;
4849 const files = await fs . readdir ( this . toolsDir ) ;
50+ console . log ( `Found files: ${ files . join ( ", " ) } ` ) ;
4951
5052 const toolPromises = files
5153 . filter ( ( file ) => this . isToolFile ( file ) )
5254 . map ( async ( file ) => {
5355 try {
54- const modulePath = `file://${ join ( this . toolsDir , file ) } ` ;
55- const { default : ToolClass } = await import ( modulePath ) ;
56+ const fullPath = join ( this . toolsDir , file ) ;
57+ console . log ( `Loading tool from: ${ fullPath } ` ) ;
58+ const { default : ToolClass } = await import ( `file://${ fullPath } ` ) ;
5659
57- if ( ! ToolClass ) return null ;
60+ if ( ! ToolClass ) {
61+ console . log ( `No default export found in ${ file } ` ) ;
62+ return null ;
63+ }
5864
5965 const tool = new ToolClass ( ) ;
60- return this . validateTool ( tool ) ? tool : null ;
61- } catch {
66+ if ( this . validateTool ( tool ) ) {
67+ console . log ( `Successfully loaded tool: ${ tool . name } ` ) ;
68+ return tool ;
69+ }
70+ console . log ( `Invalid tool found in ${ file } ` ) ;
71+ return null ;
72+ } catch ( error ) {
73+ console . error ( `Error loading tool ${ file } :` , error ) ;
6274 return null ;
6375 }
6476 } ) ;
6577
6678 const tools = ( await Promise . all ( toolPromises ) ) . filter (
6779 Boolean
6880 ) as BaseTool [ ] ;
81+ console . log (
82+ `Loaded ${ tools . length } tools: ${ tools . map ( ( t ) => t . name ) . join ( ", " ) } `
83+ ) ;
6984 return tools ;
7085 } catch ( error ) {
71- console . error ( `Failed to load tools from ${ this . toolsDir } ` ) ;
86+ console . error ( `Failed to load tools from ${ this . toolsDir } :` , error ) ;
7287 return [ ] ;
7388 }
7489 }
0 commit comments