@@ -296,8 +296,13 @@ func readTool(ctx context.Context, cache *cache.Client, prg *types.Program, base
296
296
}
297
297
298
298
func linkAll (ctx context.Context , cache * cache.Client , prg * types.Program , base * source , tools []types.Tool , localTools types.ToolSet ) (result []types.Tool , _ error ) {
299
+ localToolsMapping := make (map [string ]string , len (tools ))
300
+ for _ , localTool := range localTools {
301
+ localToolsMapping [strings .ToLower (localTool .Parameters .Name )] = localTool .ID
302
+ }
303
+
299
304
for _ , tool := range tools {
300
- tool , err := link (ctx , cache , prg , base , tool , localTools )
305
+ tool , err := link (ctx , cache , prg , base , tool , localTools , localToolsMapping )
301
306
if err != nil {
302
307
return nil , err
303
308
}
@@ -306,7 +311,7 @@ func linkAll(ctx context.Context, cache *cache.Client, prg *types.Program, base
306
311
return
307
312
}
308
313
309
- func link (ctx context.Context , cache * cache.Client , prg * types.Program , base * source , tool types.Tool , localTools types.ToolSet ) (types.Tool , error ) {
314
+ func link (ctx context.Context , cache * cache.Client , prg * types.Program , base * source , tool types.Tool , localTools types.ToolSet , localToolsMapping map [ string ] string ) (types.Tool , error ) {
310
315
if existing , ok := prg .ToolSet [tool .ID ]; ok {
311
316
return existing , nil
312
317
}
@@ -331,7 +336,7 @@ func link(ctx context.Context, cache *cache.Client, prg *types.Program, base *so
331
336
linkedTool = existing
332
337
} else {
333
338
var err error
334
- linkedTool , err = link (ctx , cache , prg , base , localTool , localTools )
339
+ linkedTool , err = link (ctx , cache , prg , base , localTool , localTools , localToolsMapping )
335
340
if err != nil {
336
341
return types.Tool {}, fmt .Errorf ("failed linking %s at %s: %w" , targetToolName , base , err )
337
342
}
@@ -351,9 +356,7 @@ func link(ctx context.Context, cache *cache.Client, prg *types.Program, base *so
351
356
}
352
357
}
353
358
354
- for _ , localTool := range localTools {
355
- tool .LocalTools [strings .ToLower (localTool .Parameters .Name )] = localTool .ID
356
- }
359
+ tool .LocalTools = localToolsMapping
357
360
358
361
tool = builtin .SetDefaults (tool )
359
362
prg .ToolSet [tool .ID ] = tool
@@ -438,7 +441,16 @@ func resolve(ctx context.Context, cache *cache.Client, prg *types.Program, base
438
441
return nil , err
439
442
}
440
443
441
- return readTool (ctx , cache , prg , s , subTool )
444
+ result , err := readTool (ctx , cache , prg , s , subTool )
445
+ if err != nil {
446
+ return nil , err
447
+ }
448
+
449
+ if len (result ) == 0 {
450
+ return nil , types .NewErrToolNotFound (types .ToToolName (name , subTool ))
451
+ }
452
+
453
+ return result , nil
442
454
}
443
455
444
456
func input (ctx context.Context , cache * cache.Client , base * source , name string ) (* source , error ) {
0 commit comments