forked from agntcy/dir
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuilder.go
More file actions
69 lines (55 loc) · 1.55 KB
/
Copy pathbuilder.go
File metadata and controls
69 lines (55 loc) · 1.55 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
// Copyright AGNTCY Contributors (https://github.com/agntcy)
// SPDX-License-Identifier: Apache-2.0
package builder
import (
"context"
"fmt"
"time"
coretypes "github.com/agntcy/dir/api/core/v1alpha1"
"github.com/agntcy/dir/cli/builder/config"
"github.com/agntcy/dir/cli/builder/plugins/llmanalyzer"
"github.com/agntcy/dir/cli/builder/plugins/pyprojectparser"
"github.com/agntcy/dir/cli/builder/plugins/runtime"
clitypes "github.com/agntcy/dir/cli/types"
)
type Builder struct {
plugins []clitypes.Builder
source string
cfg *config.Config
}
func NewBuilder(source string, cfg *config.Config) *Builder {
return &Builder{
plugins: make([]clitypes.Builder, 0),
source: source,
cfg: cfg,
}
}
func (b *Builder) RegisterPlugins() error {
if b.cfg.Builder.LLMAnalyzer {
LLMAnalyzer, err := llmanalyzer.New(b.source, b.cfg.Builder.SourceIgnore)
if err != nil {
return fmt.Errorf("failed to register LLMAnalyzer plugin: %w", err)
}
b.plugins = append(b.plugins, LLMAnalyzer)
}
if b.cfg.Builder.Runtime {
b.plugins = append(b.plugins, runtime.New(b.source))
}
if b.cfg.Builder.PyprojectParser {
b.plugins = append(b.plugins, pyprojectparser.New(b.source))
}
return nil
}
func (b *Builder) BuildAgent(ctx context.Context) (*coretypes.Agent, error) {
agent := &coretypes.Agent{
CreatedAt: time.Now().Format(time.RFC3339),
}
for _, plugin := range b.plugins {
pluginAgent, err := plugin.Build(ctx)
if err != nil {
return nil, fmt.Errorf("failed to build plugin: %w", err)
}
agent.Merge(pluginAgent)
}
return agent, nil
}