@@ -26,8 +26,8 @@ const credentialHelpersRepo = "github.com/gptscript-ai/gptscript-credential-help
26
26
27
27
type Runtime interface {
28
28
ID () string
29
- Supports (cmd []string ) bool
30
- Setup (ctx context.Context , dataRoot , toolSource string , env []string ) ([]string , error )
29
+ Supports (tool types. Tool , cmd []string ) bool
30
+ Setup (ctx context.Context , tool types. Tool , dataRoot , toolSource string , env []string ) ([]string , error )
31
31
}
32
32
33
33
type noopRuntime struct {
@@ -37,11 +37,11 @@ func (n noopRuntime) ID() string {
37
37
return "none"
38
38
}
39
39
40
- func (n noopRuntime ) Supports (_ []string ) bool {
40
+ func (n noopRuntime ) Supports (_ types. Tool , _ []string ) bool {
41
41
return false
42
42
}
43
43
44
- func (n noopRuntime ) Setup (_ context.Context , _ , _ string , _ []string ) ([]string , error ) {
44
+ func (n noopRuntime ) Setup (_ context.Context , _ types. Tool , _ , _ string , _ []string ) ([]string , error ) {
45
45
return nil , nil
46
46
}
47
47
@@ -52,7 +52,6 @@ type Manager struct {
52
52
credHelperDirs credentials.CredentialHelperDirs
53
53
runtimes []Runtime
54
54
credHelperConfig * credHelperConfig
55
- supportLocal bool
56
55
}
57
56
58
57
type credHelperConfig struct {
@@ -62,10 +61,6 @@ type credHelperConfig struct {
62
61
env []string
63
62
}
64
63
65
- func (m * Manager ) SetSupportLocal () {
66
- m .supportLocal = true
67
- }
68
-
69
64
func New (cacheDir string , runtimes ... Runtime ) * Manager {
70
65
root := filepath .Join (cacheDir , "repos" )
71
66
return & Manager {
@@ -216,7 +211,7 @@ func (m *Manager) setup(ctx context.Context, runtime Runtime, tool types.Tool, e
216
211
}
217
212
}
218
213
219
- newEnv , err := runtime .Setup (ctx , m .runtimeDir , targetFinal , env )
214
+ newEnv , err := runtime .Setup (ctx , tool , m .runtimeDir , targetFinal , env )
220
215
if err != nil {
221
216
return "" , nil , err
222
217
}
@@ -240,17 +235,10 @@ func (m *Manager) setup(ctx context.Context, runtime Runtime, tool types.Tool, e
240
235
241
236
func (m * Manager ) GetContext (ctx context.Context , tool types.Tool , cmd , env []string ) (string , []string , error ) {
242
237
var isLocal bool
243
- if ! m .supportLocal {
244
- if tool .Source .Repo == nil {
245
- return tool .WorkingDir , env , nil
246
- }
247
-
248
- if tool .Source .Repo .VCS != "git" {
249
- return "" , nil , fmt .Errorf ("only git is supported, found VCS %s for %s" , tool .Source .Repo .VCS , tool .ID )
250
- }
251
- } else if tool .Source .Repo == nil {
238
+ if tool .Source .Repo == nil {
252
239
isLocal = true
253
- id := hash .Digest (tool )[:12 ]
240
+ d , _ := json .Marshal (tool )
241
+ id := hash .Digest (d )[:12 ]
254
242
tool .Source .Repo = & types.Repo {
255
243
VCS : "<local>" ,
256
244
Root : id ,
@@ -261,7 +249,7 @@ func (m *Manager) GetContext(ctx context.Context, tool types.Tool, cmd, env []st
261
249
}
262
250
263
251
for _ , runtime := range m .runtimes {
264
- if runtime .Supports (cmd ) {
252
+ if runtime .Supports (tool , cmd ) {
265
253
log .Debugf ("Runtime %s supports %v" , runtime .ID (), cmd )
266
254
return m .setup (ctx , runtime , tool , env )
267
255
}
0 commit comments