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>
223 lines
7.5 KiB
Go
223 lines
7.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: settings.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const deleteSettingsByBotID = `-- name: DeleteSettingsByBotID :exec
|
|
UPDATE bots
|
|
SET max_context_load_time = 1440,
|
|
max_context_tokens = 0,
|
|
max_inbox_items = 50,
|
|
language = 'auto',
|
|
allow_guest = false,
|
|
reasoning_enabled = false,
|
|
reasoning_effort = 'medium',
|
|
heartbeat_enabled = false,
|
|
heartbeat_interval = 30,
|
|
heartbeat_prompt = '',
|
|
chat_model_id = NULL,
|
|
heartbeat_model_id = NULL,
|
|
search_provider_id = NULL,
|
|
memory_provider_id = NULL,
|
|
updated_at = now()
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteSettingsByBotID(ctx context.Context, id pgtype.UUID) error {
|
|
_, err := q.db.Exec(ctx, deleteSettingsByBotID, id)
|
|
return err
|
|
}
|
|
|
|
const getSettingsByBotID = `-- name: GetSettingsByBotID :one
|
|
SELECT
|
|
bots.id AS bot_id,
|
|
bots.max_context_load_time,
|
|
bots.max_context_tokens,
|
|
bots.max_inbox_items,
|
|
bots.language,
|
|
bots.allow_guest,
|
|
bots.reasoning_enabled,
|
|
bots.reasoning_effort,
|
|
bots.heartbeat_enabled,
|
|
bots.heartbeat_interval,
|
|
bots.heartbeat_prompt,
|
|
chat_models.id AS chat_model_id,
|
|
heartbeat_models.id AS heartbeat_model_id,
|
|
search_providers.id AS search_provider_id,
|
|
memory_providers.id AS memory_provider_id
|
|
FROM bots
|
|
LEFT JOIN models AS chat_models ON chat_models.id = bots.chat_model_id
|
|
LEFT JOIN models AS heartbeat_models ON heartbeat_models.id = bots.heartbeat_model_id
|
|
LEFT JOIN search_providers ON search_providers.id = bots.search_provider_id
|
|
LEFT JOIN memory_providers ON memory_providers.id = bots.memory_provider_id
|
|
WHERE bots.id = $1
|
|
`
|
|
|
|
type GetSettingsByBotIDRow struct {
|
|
BotID pgtype.UUID `json:"bot_id"`
|
|
MaxContextLoadTime int32 `json:"max_context_load_time"`
|
|
MaxContextTokens int32 `json:"max_context_tokens"`
|
|
MaxInboxItems int32 `json:"max_inbox_items"`
|
|
Language string `json:"language"`
|
|
AllowGuest bool `json:"allow_guest"`
|
|
ReasoningEnabled bool `json:"reasoning_enabled"`
|
|
ReasoningEffort string `json:"reasoning_effort"`
|
|
HeartbeatEnabled bool `json:"heartbeat_enabled"`
|
|
HeartbeatInterval int32 `json:"heartbeat_interval"`
|
|
HeartbeatPrompt string `json:"heartbeat_prompt"`
|
|
ChatModelID pgtype.UUID `json:"chat_model_id"`
|
|
HeartbeatModelID pgtype.UUID `json:"heartbeat_model_id"`
|
|
SearchProviderID pgtype.UUID `json:"search_provider_id"`
|
|
MemoryProviderID pgtype.UUID `json:"memory_provider_id"`
|
|
}
|
|
|
|
func (q *Queries) GetSettingsByBotID(ctx context.Context, id pgtype.UUID) (GetSettingsByBotIDRow, error) {
|
|
row := q.db.QueryRow(ctx, getSettingsByBotID, id)
|
|
var i GetSettingsByBotIDRow
|
|
err := row.Scan(
|
|
&i.BotID,
|
|
&i.MaxContextLoadTime,
|
|
&i.MaxContextTokens,
|
|
&i.MaxInboxItems,
|
|
&i.Language,
|
|
&i.AllowGuest,
|
|
&i.ReasoningEnabled,
|
|
&i.ReasoningEffort,
|
|
&i.HeartbeatEnabled,
|
|
&i.HeartbeatInterval,
|
|
&i.HeartbeatPrompt,
|
|
&i.ChatModelID,
|
|
&i.HeartbeatModelID,
|
|
&i.SearchProviderID,
|
|
&i.MemoryProviderID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const upsertBotSettings = `-- name: UpsertBotSettings :one
|
|
WITH updated AS (
|
|
UPDATE bots
|
|
SET max_context_load_time = $1,
|
|
max_context_tokens = $2,
|
|
max_inbox_items = $3,
|
|
language = $4,
|
|
allow_guest = $5,
|
|
reasoning_enabled = $6,
|
|
reasoning_effort = $7,
|
|
heartbeat_enabled = $8,
|
|
heartbeat_interval = $9,
|
|
heartbeat_prompt = $10,
|
|
chat_model_id = COALESCE($11::uuid, bots.chat_model_id),
|
|
heartbeat_model_id = COALESCE($12::uuid, bots.heartbeat_model_id),
|
|
search_provider_id = COALESCE($13::uuid, bots.search_provider_id),
|
|
memory_provider_id = COALESCE($14::uuid, bots.memory_provider_id),
|
|
updated_at = now()
|
|
WHERE bots.id = $15
|
|
RETURNING bots.id, bots.max_context_load_time, bots.max_context_tokens, bots.max_inbox_items, bots.language, bots.allow_guest, bots.reasoning_enabled, bots.reasoning_effort, bots.heartbeat_enabled, bots.heartbeat_interval, bots.heartbeat_prompt, bots.chat_model_id, bots.heartbeat_model_id, bots.search_provider_id, bots.memory_provider_id
|
|
)
|
|
SELECT
|
|
updated.id AS bot_id,
|
|
updated.max_context_load_time,
|
|
updated.max_context_tokens,
|
|
updated.max_inbox_items,
|
|
updated.language,
|
|
updated.allow_guest,
|
|
updated.reasoning_enabled,
|
|
updated.reasoning_effort,
|
|
updated.heartbeat_enabled,
|
|
updated.heartbeat_interval,
|
|
updated.heartbeat_prompt,
|
|
chat_models.id AS chat_model_id,
|
|
heartbeat_models.id AS heartbeat_model_id,
|
|
search_providers.id AS search_provider_id,
|
|
memory_providers.id AS memory_provider_id
|
|
FROM updated
|
|
LEFT JOIN models AS chat_models ON chat_models.id = updated.chat_model_id
|
|
LEFT JOIN models AS heartbeat_models ON heartbeat_models.id = updated.heartbeat_model_id
|
|
LEFT JOIN search_providers ON search_providers.id = updated.search_provider_id
|
|
LEFT JOIN memory_providers ON memory_providers.id = updated.memory_provider_id
|
|
`
|
|
|
|
type UpsertBotSettingsParams struct {
|
|
MaxContextLoadTime int32 `json:"max_context_load_time"`
|
|
MaxContextTokens int32 `json:"max_context_tokens"`
|
|
MaxInboxItems int32 `json:"max_inbox_items"`
|
|
Language string `json:"language"`
|
|
AllowGuest bool `json:"allow_guest"`
|
|
ReasoningEnabled bool `json:"reasoning_enabled"`
|
|
ReasoningEffort string `json:"reasoning_effort"`
|
|
HeartbeatEnabled bool `json:"heartbeat_enabled"`
|
|
HeartbeatInterval int32 `json:"heartbeat_interval"`
|
|
HeartbeatPrompt string `json:"heartbeat_prompt"`
|
|
ChatModelID pgtype.UUID `json:"chat_model_id"`
|
|
HeartbeatModelID pgtype.UUID `json:"heartbeat_model_id"`
|
|
SearchProviderID pgtype.UUID `json:"search_provider_id"`
|
|
MemoryProviderID pgtype.UUID `json:"memory_provider_id"`
|
|
ID pgtype.UUID `json:"id"`
|
|
}
|
|
|
|
type UpsertBotSettingsRow struct {
|
|
BotID pgtype.UUID `json:"bot_id"`
|
|
MaxContextLoadTime int32 `json:"max_context_load_time"`
|
|
MaxContextTokens int32 `json:"max_context_tokens"`
|
|
MaxInboxItems int32 `json:"max_inbox_items"`
|
|
Language string `json:"language"`
|
|
AllowGuest bool `json:"allow_guest"`
|
|
ReasoningEnabled bool `json:"reasoning_enabled"`
|
|
ReasoningEffort string `json:"reasoning_effort"`
|
|
HeartbeatEnabled bool `json:"heartbeat_enabled"`
|
|
HeartbeatInterval int32 `json:"heartbeat_interval"`
|
|
HeartbeatPrompt string `json:"heartbeat_prompt"`
|
|
ChatModelID pgtype.UUID `json:"chat_model_id"`
|
|
HeartbeatModelID pgtype.UUID `json:"heartbeat_model_id"`
|
|
SearchProviderID pgtype.UUID `json:"search_provider_id"`
|
|
MemoryProviderID pgtype.UUID `json:"memory_provider_id"`
|
|
}
|
|
|
|
func (q *Queries) UpsertBotSettings(ctx context.Context, arg UpsertBotSettingsParams) (UpsertBotSettingsRow, error) {
|
|
row := q.db.QueryRow(ctx, upsertBotSettings,
|
|
arg.MaxContextLoadTime,
|
|
arg.MaxContextTokens,
|
|
arg.MaxInboxItems,
|
|
arg.Language,
|
|
arg.AllowGuest,
|
|
arg.ReasoningEnabled,
|
|
arg.ReasoningEffort,
|
|
arg.HeartbeatEnabled,
|
|
arg.HeartbeatInterval,
|
|
arg.HeartbeatPrompt,
|
|
arg.ChatModelID,
|
|
arg.HeartbeatModelID,
|
|
arg.SearchProviderID,
|
|
arg.MemoryProviderID,
|
|
arg.ID,
|
|
)
|
|
var i UpsertBotSettingsRow
|
|
err := row.Scan(
|
|
&i.BotID,
|
|
&i.MaxContextLoadTime,
|
|
&i.MaxContextTokens,
|
|
&i.MaxInboxItems,
|
|
&i.Language,
|
|
&i.AllowGuest,
|
|
&i.ReasoningEnabled,
|
|
&i.ReasoningEffort,
|
|
&i.HeartbeatEnabled,
|
|
&i.HeartbeatInterval,
|
|
&i.HeartbeatPrompt,
|
|
&i.ChatModelID,
|
|
&i.HeartbeatModelID,
|
|
&i.SearchProviderID,
|
|
&i.MemoryProviderID,
|
|
)
|
|
return i, err
|
|
}
|