mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
ea719f7ca7
* refactor: memory provider * fix: migrations * feat: divide collection from different built-in memory * feat: add `MEMORY.md` and `PROFILES.md` * use .env for docker compose. fix #142 (#143) * feat(web): add brand icons for search providers (#144) Add custom FontAwesome icon definitions for all 9 search providers: - Yandex: uses existing faYandex from FA free brands - Tavily, Jina, Exa, Bocha, Serper: custom icons from brand SVGs - DuckDuckGo, SearXNG, Sogou: custom icons from Simple Icons Icons are registered with a custom 'fac' prefix and rendered as monochrome (currentColor) via FontAwesome's standard rendering. * fix: resolve multiple UI bugs (#147) * feat: add email service with multi-adapter support (#146) * feat: add email service with multi-adapter support Implement a full-stack email service with global provider management, per-bot bindings with granular read/write permissions, outbox audit storage, and MCP tool integration for direct mailbox access. Backend: - Email providers: CRUD with dynamic config schema (generic SMTP/IMAP, Mailgun) - Generic adapter: go-mail (SMTP) + go-imap/v2 (IMAP IDLE real-time push via UnilateralDataHandler + UID-based tracking + periodic check fallback) - Mailgun adapter: mailgun-go/v5 with dual inbound mode (webhook + poll) - Bot email bindings: per-bot provider binding with independent r/w permissions - Outbox: outbound email audit log with status tracking - Trigger: inbound emails push notification to bot_inbox (from/subject only, LLM reads full content on demand via MCP tools) - MailboxReader interface: on-demand IMAP queries for listing/reading emails - MCP tools: email_accounts, email_send, email_list (paginated mailbox), email_read (by UID) — all with multi-binding and provider_id selection - Webhook: /email/mailgun/webhook/:config_id (JWT-skipped, signature-verified) - DB migration: 0019_add_email (email_providers, bot_email_bindings, email_outbox) Frontend: - Email Providers page: /email-providers with MasterDetailSidebarLayout - Dynamic config form rendered from ordered provider meta schema with i18n keys - Bot detail: Email tab with bindings management + outbox audit table - Sidebar navigation entry - Full i18n support (en + zh) - Auto-generated SDK from Swagger Closes #17 * feat(email): trigger bot conversation immediately on inbound email Instead of only storing an inbox item and waiting for the next chat, the email trigger now proactively invokes the conversation resolver so the bot processes new emails right away — aligned with the schedule/heartbeat trigger pattern. * fix: lint --------- Co-authored-by: Acbox <acbox0328@gmail.com> * chore: update AGENTS.md * feat: files preview * feat(web): improve MCP details page * refactor(skills): import skill with pure markdown string * merge main into refactor/memory * fix: migration * refactor: temp delete qdrant and bm25 index * fix: clean merge code * fix: update memory handler --------- Co-authored-by: Leohearts <leohearts@leohearts.com> Co-authored-by: Menci <mencici@msn.com> Co-authored-by: Quincy <69751197+dqygit@users.noreply.github.com> Co-authored-by: BBQ <35603386+HoneyBBQ@users.noreply.github.com> Co-authored-by: Ran <16112591+chen-ran@users.noreply.github.com>
158 lines
5.0 KiB
Go
158 lines
5.0 KiB
Go
package handlers
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
memprovider "github.com/memohai/memoh/internal/memory/provider"
|
|
)
|
|
|
|
type MemoryProvidersHandler struct {
|
|
service *memprovider.Service
|
|
logger *slog.Logger
|
|
}
|
|
|
|
func NewMemoryProvidersHandler(log *slog.Logger, service *memprovider.Service) *MemoryProvidersHandler {
|
|
return &MemoryProvidersHandler{
|
|
service: service,
|
|
logger: log.With(slog.String("handler", "memory_providers")),
|
|
}
|
|
}
|
|
|
|
func (h *MemoryProvidersHandler) Register(e *echo.Echo) {
|
|
group := e.Group("/memory-providers")
|
|
group.GET("/meta", h.ListMeta)
|
|
group.POST("", h.Create)
|
|
group.GET("", h.List)
|
|
group.GET("/:id", h.Get)
|
|
group.PUT("/:id", h.Update)
|
|
group.DELETE("/:id", h.Delete)
|
|
}
|
|
|
|
// ListMeta godoc
|
|
// @Summary List memory provider metadata
|
|
// @Description List available memory provider types and config schemas
|
|
// @Tags memory-providers
|
|
// @Success 200 {array} provider.ProviderMeta
|
|
// @Router /memory-providers/meta [get]
|
|
func (h *MemoryProvidersHandler) ListMeta(c echo.Context) error {
|
|
return c.JSON(http.StatusOK, h.service.ListMeta(c.Request().Context()))
|
|
}
|
|
|
|
// Create godoc
|
|
// @Summary Create a memory provider
|
|
// @Description Create a memory provider configuration
|
|
// @Tags memory-providers
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param request body provider.ProviderCreateRequest true "Memory provider configuration"
|
|
// @Success 201 {object} provider.ProviderGetResponse
|
|
// @Failure 400 {object} ErrorResponse
|
|
// @Failure 500 {object} ErrorResponse
|
|
// @Router /memory-providers [post]
|
|
func (h *MemoryProvidersHandler) Create(c echo.Context) error {
|
|
var req memprovider.ProviderCreateRequest
|
|
if err := c.Bind(&req); err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
|
|
}
|
|
if strings.TrimSpace(req.Name) == "" {
|
|
return echo.NewHTTPError(http.StatusBadRequest, "name is required")
|
|
}
|
|
if strings.TrimSpace(string(req.Provider)) == "" {
|
|
return echo.NewHTTPError(http.StatusBadRequest, "provider is required")
|
|
}
|
|
resp, err := h.service.Create(c.Request().Context(), req)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
|
|
}
|
|
return c.JSON(http.StatusCreated, resp)
|
|
}
|
|
|
|
// List godoc
|
|
// @Summary List memory providers
|
|
// @Description List configured memory providers
|
|
// @Tags memory-providers
|
|
// @Produce json
|
|
// @Success 200 {array} provider.ProviderGetResponse
|
|
// @Failure 500 {object} ErrorResponse
|
|
// @Router /memory-providers [get]
|
|
func (h *MemoryProvidersHandler) List(c echo.Context) error {
|
|
items, err := h.service.List(c.Request().Context())
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
|
|
}
|
|
return c.JSON(http.StatusOK, items)
|
|
}
|
|
|
|
// Get godoc
|
|
// @Summary Get a memory provider
|
|
// @Description Get memory provider by ID
|
|
// @Tags memory-providers
|
|
// @Produce json
|
|
// @Param id path string true "Provider ID"
|
|
// @Success 200 {object} provider.ProviderGetResponse
|
|
// @Failure 400 {object} ErrorResponse
|
|
// @Failure 404 {object} ErrorResponse
|
|
// @Router /memory-providers/{id} [get]
|
|
func (h *MemoryProvidersHandler) Get(c echo.Context) error {
|
|
id := strings.TrimSpace(c.Param("id"))
|
|
if id == "" {
|
|
return echo.NewHTTPError(http.StatusBadRequest, "id is required")
|
|
}
|
|
resp, err := h.service.Get(c.Request().Context(), id)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusNotFound, err.Error())
|
|
}
|
|
return c.JSON(http.StatusOK, resp)
|
|
}
|
|
|
|
// Update godoc
|
|
// @Summary Update a memory provider
|
|
// @Description Update memory provider by ID
|
|
// @Tags memory-providers
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path string true "Provider ID"
|
|
// @Param request body provider.ProviderUpdateRequest true "Updated configuration"
|
|
// @Success 200 {object} provider.ProviderGetResponse
|
|
// @Failure 400 {object} ErrorResponse
|
|
// @Failure 500 {object} ErrorResponse
|
|
// @Router /memory-providers/{id} [put]
|
|
func (h *MemoryProvidersHandler) Update(c echo.Context) error {
|
|
id := strings.TrimSpace(c.Param("id"))
|
|
if id == "" {
|
|
return echo.NewHTTPError(http.StatusBadRequest, "id is required")
|
|
}
|
|
var req memprovider.ProviderUpdateRequest
|
|
if err := c.Bind(&req); err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
|
|
}
|
|
resp, err := h.service.Update(c.Request().Context(), id, req)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
|
|
}
|
|
return c.JSON(http.StatusOK, resp)
|
|
}
|
|
|
|
// Delete godoc
|
|
// @Summary Delete a memory provider
|
|
// @Description Delete memory provider by ID
|
|
// @Tags memory-providers
|
|
// @Param id path string true "Provider ID"
|
|
// @Success 204 "No Content"
|
|
// @Failure 400 {object} ErrorResponse
|
|
// @Failure 500 {object} ErrorResponse
|
|
// @Router /memory-providers/{id} [delete]
|
|
func (h *MemoryProvidersHandler) Delete(c echo.Context) error {
|
|
id := strings.TrimSpace(c.Param("id"))
|
|
if id == "" {
|
|
return echo.NewHTTPError(http.StatusBadRequest, "id is required")
|
|
}
|
|
if err := h.service.Delete(c.Request().Context(), id); err != nil {
|
|
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
|
|
}
|
|
return c.NoContent(http.StatusNoContent)
|
|
}
|