Move views

This commit is contained in:
Ettore Di Giacinto
2024-04-11 00:16:03 +02:00
parent 3b361d1a3d
commit f85962769a
9 changed files with 46 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"embed"
"fmt"
"log"
"math/rand"
@@ -10,6 +11,7 @@ import (
"github.com/donseba/go-htmx"
fiber "github.com/gofiber/fiber/v2"
"github.com/gofiber/template/html/v2"
. "github.com/mudler/local-agent-framework/agent"
"github.com/mudler/local-agent-framework/llm"
@@ -46,6 +48,9 @@ func htmlIfy(s string) string {
return s
}
//go:embed views/*
var viewsfs embed.FS
func main() {
// current dir
cwd, err := os.Getwd()
@@ -96,27 +101,30 @@ func main() {
if err := pool.StartAll(); err != nil {
panic(err)
}
engine := html.NewFileSystem(http.FS(viewsfs), ".html")
// Initialize a new Fiber app
webapp := fiber.New()
// Pass the engine to the Views
webapp := fiber.New(fiber.Config{
Views: engine,
})
// Serve static files
webapp.Static("/", "./public")
webapp.Get("/", func(c *fiber.Ctx) error {
return c.Render("index.html", fiber.Map{
return c.Render("views/index", fiber.Map{
"Agents": pool.List(),
})
})
webapp.Get("/agents", func(c *fiber.Ctx) error {
return c.Render("agents.html", fiber.Map{
return c.Render("views/agents", fiber.Map{
"Agents": pool.List(),
})
})
webapp.Get("/create", func(c *fiber.Ctx) error {
return c.Render("create.html", fiber.Map{
return c.Render("views/create", fiber.Map{
"Title": "Hello, World!",
"Actions": AvailableActions,
"Connectors": AvailableConnectors,
@@ -124,7 +132,7 @@ func main() {
})
webapp.Get("/knowledgebase", func(c *fiber.Ctx) error {
return c.Render("knowledgebase.html", fiber.Map{
return c.Render("views/knowledgebase", fiber.Map{
"Title": "Hello, World!",
"KnowledgebaseItemsCount": len(db.Database),
})

View File

@@ -2,19 +2,19 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Agent List</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
{{template "views/partials/header"}}
</head>
<body class="bg-gray-900 p-4 text-white">
<div class="max-w-6xl mx-auto">
<div class="text-center mb-6">
<h1 class="text-2xl font-bold">Smart Agent List</h1>
<h1 class="text-3xl md:text-4xl font-bold">Smart Agent List</h1>
</div>
<div class="flex flex-col">
<div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
<div class="shadow overflow-hidden border-b border-gray-700 sm:rounded-lg">
<div class="overflow-x-auto">
<div class="py-2 align-middle inline-block min-w-full">
<div class="shadow overflow-hidden border-b border-gray-700 rounded-lg">
<table class="min-w-full divide-y divide-gray-700">
<thead class="bg-gray-700">
<tr>
@@ -39,10 +39,10 @@
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-300">{{.}}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">Online</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<a href="/talk/{{.}}" class="text-blue-500 hover:text-blue-400">Talk</a>
<a href="/talk/{{.}}" class="text-indigo-500 hover:text-indigo-400">Talk</a>
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<a href="/delete/{{.}}" class="text-blue-500 hover:text-blue-400">Delete</a>
<a href="/delete/{{.}}" class="text-red-500 hover:text-red-400">Delete</a>
</td>
</tr>
{{ end }}
@@ -53,8 +53,8 @@
</div>
</div>
</div>
<div class="mt-6">
<a href="/create" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
<div class="mt-6 text-center">
<a href="/create" class="bg-indigo-500 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out">
Add New Agent
</a>
</div>

View File

@@ -1,10 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Smart Agent Interface</title>
<!-- Include Tailwind CSS from CDN -->
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
{{template "views/partials/header"}}
<!-- Optional: Include HTMX and SSE Extension for dynamic updates -->
<script src="https://unpkg.com/htmx.org"></script>
<script src="https://unpkg.com/htmx.org/dist/ext/sse.js"></script>

View File

@@ -1,9 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Create New Agent</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
{{template "views/partials/header"}}
<script src="https://unpkg.com/htmx.org"></script>
<script src="https://unpkg.com/htmx.org/dist/ext/sse.js"></script>
<script src="https://unpkg.com/hyperscript.org@0.9.12"></script>

View File

@@ -1,9 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Smart Assistant Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
{{template "views/partials/header"}}
</head>
<body class="bg-gray-900 p-4 text-white">
<div class="max-w-4xl mx-auto">

View File

@@ -1,9 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>KnowledgeBase</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
{{template "views/partials/header"}}
<script src="https://unpkg.com/htmx.org"></script>
<script src="https://unpkg.com/htmx.org/dist/ext/sse.js"></script>
<script src="https://unpkg.com/hyperscript.org@0.9.12"></script>

View File

@@ -0,0 +1,9 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Roboto', sans-serif;
}
</style>