This commit is contained in:
mudler
2024-04-08 11:15:36 +02:00
parent 7adcce78be
commit 185fb89d39
7 changed files with 120 additions and 51 deletions

View File

@@ -88,7 +88,8 @@ func main() {
webapp.Get("/create", func(c *fiber.Ctx) error {
return c.Render("create.html", fiber.Map{
"Title": "Hello, World!",
"Title": "Hello, World!",
"Actions": AvailableActions,
})
})
@@ -107,6 +108,7 @@ func main() {
webapp.Get("/notify/:name", app.Notify(pool))
webapp.Post("/chat/:name", app.Chat(pool))
webapp.Post("/create", app.Create(pool))
webapp.Get("/delete/:name", app.Delete(pool))
webapp.Get("/talk/:name", func(c *fiber.Ctx) error {
return c.Render("chat.html", fiber.Map{
@@ -166,6 +168,16 @@ func (a *App) Notify(pool *AgentPool) func(c *fiber.Ctx) error {
}
}
func (a *App) Delete(pool *AgentPool) func(c *fiber.Ctx) error {
return func(c *fiber.Ctx) error {
if err := pool.Remove(c.Params("name")); err != nil {
fmt.Println("Error removing agent", err)
return c.Status(http.StatusInternalServerError).SendString(err.Error())
}
return c.Redirect("/")
}
}
func (a *App) Create(pool *AgentPool) func(c *fiber.Ctx) error {
return func(c *fiber.Ctx) error {
config := AgentConfig{}
@@ -173,6 +185,8 @@ func (a *App) Create(pool *AgentPool) func(c *fiber.Ctx) error {
return err
}
fmt.Printf("Agent configuration: %+v\n", config)
if config.Name == "" {
c.Status(http.StatusBadRequest).SendString("Name is required")
return nil
@@ -223,7 +237,7 @@ func (a *App) Chat(pool *AgentPool) func(c *fiber.Ctx) error {
).WithEvent("messages"))
manager.Send(
NewMessage(
inputMessageDisabled(false), // show again the input
disabledElement("inputMessage", false), // show again the input
).WithEvent("message_status"))
//result := `<i>done</i>`
@@ -232,7 +246,7 @@ func (a *App) Chat(pool *AgentPool) func(c *fiber.Ctx) error {
manager.Send(
NewMessage(
loader() + inputMessageDisabled(true),
loader() + disabledElement("inputMessage", true),
).WithEvent("message_status"))
return nil