Files
Memoh/internal/memory/provider/provider.go
T
Acbox Liu ea719f7ca7 refactor: memory provider (#140)
* 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>
2026-03-03 15:33:50 +08:00

49 lines
1.9 KiB
Go

package provider
import (
"context"
"github.com/memohai/memoh/internal/mcp"
)
// Provider is the unified interface for memory systems. Each provider type
// (builtin, mem0, openmemory, etc.) implements this independently with its
// own storage, retrieval, and tool logic.
type Provider interface {
// Type returns the provider type identifier (e.g. "builtin", "mem0").
Type() string
// --- Conversation Hooks ---
// OnBeforeChat is called before sending to the agent gateway.
// It returns memory context to inject into the conversation, or nil if none.
OnBeforeChat(ctx context.Context, req BeforeChatRequest) (*BeforeChatResult, error)
// OnAfterChat is called after receiving the gateway response.
// It extracts facts from the conversation and stores them.
OnAfterChat(ctx context.Context, req AfterChatRequest) error
// --- MCP Tools ---
// ListTools returns MCP tool descriptors provided by this memory provider.
ListTools(ctx context.Context, session mcp.ToolSessionContext) ([]mcp.ToolDescriptor, error)
// CallTool executes an MCP tool owned by this memory provider.
CallTool(ctx context.Context, session mcp.ToolSessionContext, toolName string, arguments map[string]any) (map[string]any, error)
// --- CRUD ---
Add(ctx context.Context, req AddRequest) (SearchResponse, error)
Search(ctx context.Context, req SearchRequest) (SearchResponse, error)
GetAll(ctx context.Context, req GetAllRequest) (SearchResponse, error)
Update(ctx context.Context, req UpdateRequest) (MemoryItem, error)
Delete(ctx context.Context, memoryID string) (DeleteResponse, error)
DeleteBatch(ctx context.Context, memoryIDs []string) (DeleteResponse, error)
DeleteAll(ctx context.Context, req DeleteAllRequest) (DeleteResponse, error)
// --- Lifecycle ---
Compact(ctx context.Context, filters map[string]any, ratio float64, decayDays int) (CompactResult, error)
Usage(ctx context.Context, filters map[string]any) (UsageResponse, error)
}