Generate connector form based on meta-data (#62)
* Ignore volumes and exe * Export form meta-data * use dynamic metaform for connectors * fix populating form
This commit is contained in:
committed by
GitHub
parent
43a46ad1fb
commit
d7cfa7f0b2
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/mudler/LocalAgent/core/agent"
|
||||
"github.com/mudler/LocalAgent/pkg/metaform"
|
||||
"github.com/mudler/LocalAgent/pkg/xlog"
|
||||
)
|
||||
|
||||
@@ -37,6 +38,27 @@ func (d *Discord) AgentReasoningCallback() func(state agent.ActionCurrentState)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Discord) ConfigForm() metaform.Form {
|
||||
return metaform.Form{
|
||||
Fields: []metaform.Field{
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "token",
|
||||
Label: "Bot Token",
|
||||
Required: true,
|
||||
Placeholder: "Your Discord bot token",
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "defaultChannel",
|
||||
Label: "Default Channel",
|
||||
Required: true,
|
||||
Placeholder: "The default channel for the bot to join",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Discord) Start(a *agent.Agent) {
|
||||
|
||||
Token := d.token
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/google/go-github/v69/github"
|
||||
"github.com/mudler/LocalAgent/core/agent"
|
||||
"github.com/mudler/LocalAgent/pkg/metaform"
|
||||
"github.com/mudler/LocalAgent/pkg/xlog"
|
||||
|
||||
"github.com/sashabaranov/go-openai"
|
||||
@@ -63,6 +64,51 @@ func (g *GithubIssues) AgentReasoningCallback() func(state agent.ActionCurrentSt
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubIssues) ConfigForm() metaform.Form {
|
||||
return metaform.Form{
|
||||
Fields: []metaform.Field{
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "token",
|
||||
Label: "GitHub Token",
|
||||
Required: true,
|
||||
Placeholder: "Your GitHub personal access token",
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "owner",
|
||||
Label: "Repository Owner",
|
||||
Required: true,
|
||||
Placeholder: "username or organization",
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "repository",
|
||||
Label: "Repository Name",
|
||||
Required: true,
|
||||
Placeholder: "repo-name",
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldOptions,
|
||||
Name: "replyIfNoReplies",
|
||||
Label: "Reply Behavior",
|
||||
Required: true,
|
||||
Options: []metaform.Option{
|
||||
{Value: "true", Label: "Reply only to issues with no comments"},
|
||||
{Value: "false", Label: "Reply to all issues"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "pollInterval",
|
||||
Label: "Poll Interval",
|
||||
Required: false,
|
||||
Placeholder: "10m",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubIssues) Start(a *agent.Agent) {
|
||||
// Start the connector
|
||||
g.agent = a
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/google/go-github/v69/github"
|
||||
"github.com/mudler/LocalAgent/core/agent"
|
||||
"github.com/mudler/LocalAgent/pkg/metaform"
|
||||
"github.com/mudler/LocalAgent/pkg/xlog"
|
||||
|
||||
"github.com/sashabaranov/go-openai"
|
||||
@@ -63,6 +64,51 @@ func (g *GithubPRs) AgentReasoningCallback() func(state agent.ActionCurrentState
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubPRs) ConfigForm() metaform.Form {
|
||||
return metaform.Form{
|
||||
Fields: []metaform.Field{
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "token",
|
||||
Label: "GitHub Token",
|
||||
Required: true,
|
||||
Placeholder: "Your GitHub personal access token",
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "owner",
|
||||
Label: "Repository Owner",
|
||||
Required: true,
|
||||
Placeholder: "username or organization",
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "repository",
|
||||
Label: "Repository Name",
|
||||
Required: true,
|
||||
Placeholder: "repo-name",
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldOptions,
|
||||
Name: "replyIfNoReplies",
|
||||
Label: "Reply Behavior",
|
||||
Required: true,
|
||||
Options: []metaform.Option{
|
||||
{Value: "true", Label: "Reply only to PRs with no comments"},
|
||||
{Value: "false", Label: "Reply to all PRs"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "pollInterval",
|
||||
Label: "Poll Interval",
|
||||
Required: true,
|
||||
Placeholder: "10m",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubPRs) Start(a *agent.Agent) {
|
||||
// Start the connector
|
||||
g.agent = a
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/mudler/LocalAgent/core/agent"
|
||||
"github.com/mudler/LocalAgent/pkg/metaform"
|
||||
"github.com/mudler/LocalAgent/pkg/xlog"
|
||||
"github.com/mudler/LocalAgent/services/actions"
|
||||
irc "github.com/thoj/go-ircevent"
|
||||
@@ -43,6 +44,51 @@ func (i *IRC) AgentReasoningCallback() func(state agent.ActionCurrentState) bool
|
||||
}
|
||||
}
|
||||
|
||||
func (i *IRC) ConfigForm() metaform.Form {
|
||||
return metaform.Form{
|
||||
Fields: []metaform.Field{
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "server",
|
||||
Label: "Server",
|
||||
Required: true,
|
||||
Placeholder: "chat.freenode.net",
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "port",
|
||||
Label: "Port",
|
||||
Required: true,
|
||||
Placeholder: "6667",
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "nickname",
|
||||
Label: "Nickname",
|
||||
Required: true,
|
||||
Placeholder: "LocalAgentBot",
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "channel",
|
||||
Label: "Channel",
|
||||
Required: true,
|
||||
Placeholder: "#general",
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldOptions,
|
||||
Name: "alwaysReply",
|
||||
Label: "Always Reply",
|
||||
Required: true,
|
||||
Options: []metaform.Option{
|
||||
{Value: "false", Label: "Only when mentioned"},
|
||||
{Value: "true", Label: "Reply to all messages"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// cleanUpUsernameFromMessage removes the bot's nickname from the message
|
||||
func cleanUpMessage(message string, nickname string) string {
|
||||
cleaned := strings.ReplaceAll(message, nickname+":", "")
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/mudler/LocalAgent/pkg/metaform"
|
||||
"github.com/mudler/LocalAgent/pkg/xlog"
|
||||
"github.com/mudler/LocalAgent/services/actions"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
@@ -52,6 +53,44 @@ func (t *Slack) AgentReasoningCallback() func(state agent.ActionCurrentState) bo
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Slack) ConfigForm() metaform.Form {
|
||||
return metaform.Form{
|
||||
Fields: []metaform.Field{
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "appToken",
|
||||
Label: "App Token",
|
||||
Required: true,
|
||||
Placeholder: "xapp-...",
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "botToken",
|
||||
Label: "Bot Token",
|
||||
Required: true,
|
||||
Placeholder: "xoxb-...",
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "channelID",
|
||||
Label: "Channel ID",
|
||||
Required: false,
|
||||
Placeholder: "C12345678",
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldOptions,
|
||||
Name: "alwaysReply",
|
||||
Label: "Always Reply",
|
||||
Required: false,
|
||||
Options: []metaform.Option{
|
||||
{Value: "false", Label: "Only when mentioned"},
|
||||
{Value: "true", Label: "Reply to all messages"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func cleanUpUsernameFromMessage(message string, b *slack.AuthTestResponse) string {
|
||||
cleaned := strings.ReplaceAll(message, "<@"+b.UserID+">", "")
|
||||
cleaned = strings.ReplaceAll(cleaned, "<@"+b.BotID+">", "")
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/go-telegram/bot"
|
||||
"github.com/go-telegram/bot/models"
|
||||
"github.com/mudler/LocalAgent/core/agent"
|
||||
"github.com/mudler/LocalAgent/pkg/metaform"
|
||||
)
|
||||
|
||||
type Telegram struct {
|
||||
@@ -37,6 +38,20 @@ func (t *Telegram) AgentReasoningCallback() func(state agent.ActionCurrentState)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Telegram) ConfigForm() metaform.Form {
|
||||
return metaform.Form{
|
||||
Fields: []metaform.Field{
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "token",
|
||||
Label: "Bot Token",
|
||||
Required: true,
|
||||
Placeholder: "Your Telegram bot token from @BotFather",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Telegram) Start(a *agent.Agent) {
|
||||
ctx, cancel := signal.NotifyContext(a.Context(), os.Interrupt)
|
||||
defer cancel()
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"os/signal"
|
||||
|
||||
"github.com/mudler/LocalAgent/core/agent"
|
||||
"github.com/mudler/LocalAgent/pkg/metaform"
|
||||
"github.com/mudler/LocalAgent/pkg/xlog"
|
||||
"github.com/mudler/LocalAgent/services/connectors/twitter"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
@@ -32,6 +33,37 @@ func (t *Twitter) AgentReasoningCallback() func(state agent.ActionCurrentState)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Twitter) ConfigForm() metaform.Form {
|
||||
return metaform.Form{
|
||||
Fields: []metaform.Field{
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "token",
|
||||
Label: "Token",
|
||||
Required: true,
|
||||
Placeholder: "elmo-...",
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldString,
|
||||
Name: "botUsername",
|
||||
Label: "Bot Username",
|
||||
Required: true,
|
||||
Placeholder: "Chocolate Pineapple",
|
||||
},
|
||||
{
|
||||
Kind: metaform.FieldOptions,
|
||||
Name: "noCharacterLimit",
|
||||
Label: "No Character Limit",
|
||||
Required: false,
|
||||
Options: []metaform.Option{
|
||||
{Value: "false", Label: ""},
|
||||
{Value: "true", Label: ""},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func NewTwitterConnector(config map[string]string) (*Twitter, error) {
|
||||
return &Twitter{
|
||||
token: config["token"],
|
||||
|
||||
Reference in New Issue
Block a user