Refactorings
This commit is contained in:
@@ -1,88 +0,0 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/mudler/LocalAgent/core/action"
|
||||
"github.com/mudler/LocalAgent/core/state"
|
||||
"github.com/mudler/LocalAgent/pkg/xlog"
|
||||
|
||||
"github.com/mudler/LocalAgent/core/agent"
|
||||
"github.com/mudler/LocalAgent/services/actions"
|
||||
)
|
||||
|
||||
const (
|
||||
// Actions
|
||||
ActionSearch = "search"
|
||||
ActionCustom = "custom"
|
||||
ActionGithubIssueLabeler = "github-issue-labeler"
|
||||
ActionGithubIssueOpener = "github-issue-opener"
|
||||
ActionGithubIssueCloser = "github-issue-closer"
|
||||
ActionGithubIssueSearcher = "github-issue-searcher"
|
||||
ActionScraper = "scraper"
|
||||
ActionWikipedia = "wikipedia"
|
||||
ActionBrowse = "browse"
|
||||
ActionSendMail = "send_mail"
|
||||
ActionGenerateImage = "generate_image"
|
||||
)
|
||||
|
||||
var AvailableActions = []string{
|
||||
ActionSearch,
|
||||
ActionCustom,
|
||||
ActionGithubIssueLabeler,
|
||||
ActionGithubIssueOpener,
|
||||
ActionGithubIssueCloser,
|
||||
ActionGithubIssueSearcher,
|
||||
ActionScraper,
|
||||
ActionBrowse,
|
||||
ActionWikipedia,
|
||||
ActionSendMail,
|
||||
ActionGenerateImage,
|
||||
}
|
||||
|
||||
func Actions(a *state.AgentConfig) func(ctx context.Context) []agent.Action {
|
||||
return func(ctx context.Context) []agent.Action {
|
||||
allActions := []agent.Action{}
|
||||
|
||||
for _, a := range a.Actions {
|
||||
var config map[string]string
|
||||
if err := json.Unmarshal([]byte(a.Config), &config); err != nil {
|
||||
xlog.Error("Error unmarshalling action config", "error", err)
|
||||
continue
|
||||
}
|
||||
|
||||
switch a.Name {
|
||||
case ActionCustom:
|
||||
customAction, err := action.NewCustom(config, "")
|
||||
if err != nil {
|
||||
xlog.Error("Error creating custom action", "error", err)
|
||||
continue
|
||||
}
|
||||
allActions = append(allActions, customAction)
|
||||
case ActionGenerateImage:
|
||||
allActions = append(allActions, actions.NewGenImage(config))
|
||||
case ActionSearch:
|
||||
allActions = append(allActions, actions.NewSearch(config))
|
||||
case ActionGithubIssueLabeler:
|
||||
allActions = append(allActions, actions.NewGithubIssueLabeler(ctx, config))
|
||||
case ActionGithubIssueOpener:
|
||||
allActions = append(allActions, actions.NewGithubIssueOpener(ctx, config))
|
||||
case ActionGithubIssueCloser:
|
||||
allActions = append(allActions, actions.NewGithubIssueCloser(ctx, config))
|
||||
case ActionGithubIssueSearcher:
|
||||
allActions = append(allActions, actions.NewGithubIssueSearch(ctx, config))
|
||||
case ActionScraper:
|
||||
allActions = append(allActions, actions.NewScraper(config))
|
||||
case ActionWikipedia:
|
||||
allActions = append(allActions, actions.NewWikipedia(config))
|
||||
case ActionBrowse:
|
||||
allActions = append(allActions, actions.NewBrowse(config))
|
||||
case ActionSendMail:
|
||||
allActions = append(allActions, actions.NewSendMail(config))
|
||||
}
|
||||
}
|
||||
|
||||
return allActions
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/mudler/LocalAgent/pkg/xlog"
|
||||
"github.com/mudler/LocalAgent/services/connectors"
|
||||
|
||||
"github.com/mudler/LocalAgent/core/state"
|
||||
)
|
||||
|
||||
const (
|
||||
// Connectors
|
||||
ConnectorTelegram = "telegram"
|
||||
ConnectorSlack = "slack"
|
||||
ConnectorDiscord = "discord"
|
||||
ConnectorGithubIssues = "github-issues"
|
||||
ConnectorGithubPRs = "github-prs"
|
||||
)
|
||||
|
||||
var AvailableConnectors = []string{
|
||||
ConnectorTelegram,
|
||||
ConnectorSlack,
|
||||
ConnectorDiscord,
|
||||
ConnectorGithubIssues,
|
||||
ConnectorGithubPRs,
|
||||
}
|
||||
|
||||
func Connectors(a *state.AgentConfig) []state.Connector {
|
||||
conns := []state.Connector{}
|
||||
|
||||
for _, c := range a.Connector {
|
||||
var config map[string]string
|
||||
if err := json.Unmarshal([]byte(c.Config), &config); err != nil {
|
||||
xlog.Info("Error unmarshalling connector config", err)
|
||||
continue
|
||||
}
|
||||
switch c.Type {
|
||||
case ConnectorTelegram:
|
||||
cc, err := connectors.NewTelegramConnector(config)
|
||||
if err != nil {
|
||||
xlog.Info("Error creating telegram connector", err)
|
||||
continue
|
||||
}
|
||||
|
||||
conns = append(conns, cc)
|
||||
case ConnectorSlack:
|
||||
conns = append(conns, connectors.NewSlack(config))
|
||||
case ConnectorDiscord:
|
||||
conns = append(conns, connectors.NewDiscord(config))
|
||||
case ConnectorGithubIssues:
|
||||
conns = append(conns, connectors.NewGithubIssueWatcher(config))
|
||||
case ConnectorGithubPRs:
|
||||
conns = append(conns, connectors.NewGithubPRWatcher(config))
|
||||
}
|
||||
}
|
||||
return conns
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/mudler/LocalAgent/pkg/xlog"
|
||||
|
||||
"github.com/mudler/LocalAgent/core/agent"
|
||||
"github.com/mudler/LocalAgent/core/state"
|
||||
)
|
||||
|
||||
const (
|
||||
// Connectors
|
||||
DynamicPromptCustom = "custom"
|
||||
)
|
||||
|
||||
var AvailableBlockPrompts = []string{
|
||||
DynamicPromptCustom,
|
||||
}
|
||||
|
||||
func PromptBlocks(a *state.AgentConfig) []agent.PromptBlock {
|
||||
promptblocks := []agent.PromptBlock{}
|
||||
|
||||
for _, c := range a.PromptBlocks {
|
||||
var config map[string]string
|
||||
if err := json.Unmarshal([]byte(c.Config), &config); err != nil {
|
||||
xlog.Info("Error unmarshalling connector config", err)
|
||||
continue
|
||||
}
|
||||
switch c.Type {
|
||||
case DynamicPromptCustom:
|
||||
prompt, err := agent.NewDynamicPrompt(config, "")
|
||||
if err != nil {
|
||||
xlog.Error("Error creating custom prompt", "error", err)
|
||||
continue
|
||||
}
|
||||
promptblocks = append(promptblocks, prompt)
|
||||
}
|
||||
}
|
||||
return promptblocks
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/mudler/LocalAgent/core/agent"
|
||||
"github.com/mudler/LocalAgent/core/sse"
|
||||
"github.com/mudler/LocalAgent/core/state"
|
||||
"github.com/mudler/LocalAgent/services"
|
||||
)
|
||||
|
||||
//go:embed views/*
|
||||
@@ -45,9 +46,9 @@ func (app *App) registerRoutes(pool *state.AgentPool, webapp *fiber.App) {
|
||||
|
||||
webapp.Get("/create", func(c *fiber.Ctx) error {
|
||||
return c.Render("views/create", fiber.Map{
|
||||
"Actions": AvailableActions,
|
||||
"Connectors": AvailableConnectors,
|
||||
"PromptBlocks": AvailableBlockPrompts,
|
||||
"Actions": services.AvailableActions,
|
||||
"Connectors": services.AvailableConnectors,
|
||||
"PromptBlocks": services.AvailableBlockPrompts,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -97,8 +98,6 @@ func (app *App) registerRoutes(pool *state.AgentPool, webapp *fiber.App) {
|
||||
})
|
||||
webapp.Post("/settings/import", app.ImportAgent(pool))
|
||||
webapp.Get("/settings/export/:name", app.ExportAgent(pool))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
|
||||
Reference in New Issue
Block a user