Skip to content

Commit a1a6b96

Browse files
committed
Add logging, error handling
1 parent 0183466 commit a1a6b96

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

packages/core/src/custom-tools/custom-tool-registry.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,32 +78,40 @@ export class CustomToolRegistry {
7878
async loadFromDirectory(toolDir: string): Promise<LoadResult> {
7979
const result: LoadResult = { loaded: [], failed: [] }
8080

81-
if (!fs.existsSync(toolDir)) {
82-
return result
83-
}
81+
try {
82+
if (!fs.existsSync(toolDir)) {
83+
return result
84+
}
8485

85-
const files = fs.readdirSync(toolDir).filter((f) => f.endsWith(".ts") || f.endsWith(".js"))
86+
const files = fs.readdirSync(toolDir).filter((f) => f.endsWith(".ts") || f.endsWith(".js"))
8687

87-
for (const file of files) {
88-
const filePath = path.join(toolDir, file)
88+
for (const file of files) {
89+
const filePath = path.join(toolDir, file)
8990

90-
try {
91-
const mod = await this.importTypeScript(filePath)
91+
try {
92+
console.log(`[CustomToolRegistry] importing tool from ${filePath}`)
93+
const mod = await this.importTypeScript(filePath)
9294

93-
for (const [exportName, value] of Object.entries(mod)) {
94-
const def = this.validateToolDefinition(exportName, value)
95+
for (const [exportName, value] of Object.entries(mod)) {
96+
const def = this.validateToolDefinition(exportName, value)
9597

96-
if (!def) {
97-
continue
98-
}
98+
if (!def) {
99+
continue
100+
}
99101

100-
this.tools.set(def.name, def)
101-
result.loaded.push(def.name)
102+
this.tools.set(def.name, def)
103+
console.log(`[CustomToolRegistry] loaded tool ${def.name} from ${filePath}`)
104+
result.loaded.push(def.name)
105+
}
106+
} catch (error) {
107+
const message = error instanceof Error ? error.message : String(error)
108+
console.error(`[CustomToolRegistry] importTypeScript(${filePath}) failed: ${message}`)
109+
result.failed.push({ file, error: message })
102110
}
103-
} catch (error) {
104-
const message = error instanceof Error ? error.message : String(error)
105-
result.failed.push({ file, error: message })
106111
}
112+
} catch (error) {
113+
const message = error instanceof Error ? error.message : String(error)
114+
console.error(`[CustomToolRegistry] loadFromDirectory(${toolDir}) failed: ${message}`)
107115
}
108116

109117
return result

0 commit comments

Comments
 (0)