@@ -20,6 +20,7 @@ import (
20
20
21
21
"github.com/gptscript-ai/gptscript/pkg/assemble"
22
22
"github.com/gptscript-ai/gptscript/pkg/builtin"
23
+ "github.com/gptscript-ai/gptscript/pkg/engine"
23
24
"github.com/gptscript-ai/gptscript/pkg/parser"
24
25
"github.com/gptscript-ai/gptscript/pkg/types"
25
26
)
@@ -137,7 +138,7 @@ func loadURL(ctx context.Context, base *Source, name string) (*Source, bool, err
137
138
}, true , nil
138
139
}
139
140
140
- func loadProgram (data []byte , into * types.Program ) (types.Tool , error ) {
141
+ func loadProgram (data []byte , into * types.Program , targetToolName string ) (types.Tool , error ) {
141
142
var (
142
143
ext types.Program
143
144
id string
@@ -158,7 +159,19 @@ func loadProgram(data []byte, into *types.Program) (types.Tool, error) {
158
159
into .ToolSet [v .ID ] = v
159
160
}
160
161
161
- return into .ToolSet [ext .EntryToolID + id ], nil
162
+ tool := into .ToolSet [ext .EntryToolID + id ]
163
+ if targetToolName == "" {
164
+ return tool , nil
165
+ }
166
+
167
+ tool , ok := into.ToolSet [tool.LocalTools [targetToolName ]]
168
+ if ! ok {
169
+ return tool , & engine.ErrToolNotFound {
170
+ ToolName : targetToolName ,
171
+ }
172
+ }
173
+
174
+ return tool , nil
162
175
}
163
176
164
177
func ReadTool (ctx context.Context , prg * types.Program , base * Source , targetToolName string ) (types.Tool , error ) {
@@ -169,7 +182,7 @@ func ReadTool(ctx context.Context, prg *types.Program, base *Source, targetToolN
169
182
_ = base .Content .Close ()
170
183
171
184
if bytes .HasPrefix (data , assemble .Header ) {
172
- return loadProgram (data , prg )
185
+ return loadProgram (data , prg , targetToolName )
173
186
}
174
187
175
188
tools , err := parser .Parse (bytes .NewReader (data ))
@@ -263,6 +276,7 @@ func link(ctx context.Context, prg *types.Program, base *Source, tool types.Tool
263
276
}
264
277
265
278
tool .ToolMapping = map [string ]string {}
279
+ tool .LocalTools = map [string ]string {}
266
280
toolNames := map [string ]struct {}{}
267
281
268
282
// Add now to break circular loops, but later we will update this tool and copy the new
@@ -315,6 +329,10 @@ func link(ctx context.Context, prg *types.Program, base *Source, tool types.Tool
315
329
tool .Tools [i ] = newToolName
316
330
}
317
331
332
+ for _ , localTool := range localTools {
333
+ tool .LocalTools [localTool .Name ] = localTool .ID
334
+ }
335
+
318
336
tool = builtin .SetDefaults (tool )
319
337
prg .ToolSet [tool .ID ] = tool
320
338
0 commit comments