-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep_provider_testconn.go
More file actions
89 lines (79 loc) · 2.17 KB
/
step_provider_testconn.go
File metadata and controls
89 lines (79 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package agent
import (
"context"
"fmt"
"github.com/GoCodeAlone/modular"
"github.com/GoCodeAlone/workflow/module"
"github.com/GoCodeAlone/workflow/plugin"
)
// ProviderTestStep tests connectivity to a configured AI provider.
type ProviderTestStep struct {
name string
aliasExpr string
app modular.Application
tmpl *module.TemplateEngine
}
func (s *ProviderTestStep) Name() string { return s.name }
func (s *ProviderTestStep) Execute(ctx context.Context, pc *module.PipelineContext) (*module.StepResult, error) {
var alias string
if s.aliasExpr != "" {
raw, err := s.tmpl.Resolve(s.aliasExpr, pc)
if err != nil {
return nil, fmt.Errorf("provider_test step %q: resolve alias: %w", s.name, err)
}
alias = fmt.Sprintf("%v", raw)
}
if alias == "" {
alias = extractString(pc.Current, "alias", "")
}
if alias == "" {
return nil, fmt.Errorf("provider_test step %q: alias is required", s.name)
}
// Lazy-lookup ProviderRegistry
for _, regSvcName := range []string{"agent-provider-registry", "ratchet-provider-registry"} {
svc, ok := s.app.SvcRegistry()[regSvcName]
if !ok {
continue
}
registry, ok := svc.(*ProviderRegistry)
if !ok {
continue
}
success, message, latency, err := registry.TestConnection(ctx, alias)
if err != nil {
return &module.StepResult{
Output: map[string]any{
"success": false,
"message": message,
"latency_ms": latency.Milliseconds(),
},
}, nil
}
return &module.StepResult{
Output: map[string]any{
"success": success,
"message": message,
"latency_ms": latency.Milliseconds(),
},
}, nil
}
return &module.StepResult{
Output: map[string]any{
"success": false,
"message": "provider registry not available",
"latency_ms": 0,
},
}, nil
}
// newProviderTestFactory returns a plugin.StepFactory for "step.provider_test".
func newProviderTestFactory() plugin.StepFactory {
return func(name string, cfg map[string]any, app modular.Application) (any, error) {
aliasExpr, _ := cfg["alias"].(string)
return &ProviderTestStep{
name: name,
aliasExpr: aliasExpr,
app: app,
tmpl: module.NewTemplateEngine(),
}, nil
}
}