refactor(core): restructure conversation, channel and message domains

- Rename chat module to conversation with flow-based architecture
- Move channelidentities into channel/identities subpackage
- Add channel/route for routing logic
- Add message service with event hub
- Add MCP providers: container, directory, schedule
- Refactor Feishu/Telegram adapters with directory and stream support
- Add platform management page and channel badges in web UI
- Update database schema for conversations, messages and channel routes
- Add @memoh/shared package for cross-package type definitions
This commit is contained in:
BBQ
2026-02-12 15:33:09 +08:00
parent 75e2ef0467
commit ca5c6a1866
243 changed files with 21463 additions and 10485 deletions
+37 -69
View File
@@ -15,6 +15,7 @@ type Bot struct {
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
IsActive bool `json:"is_active"`
Status string `json:"status"`
MaxContextLoadTime int32 `json:"max_context_load_time"`
Language string `json:"language"`
AllowGuest bool `json:"allow_guest"`
@@ -41,6 +42,34 @@ type BotChannelConfig struct {
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
type BotChannelRoute struct {
ID pgtype.UUID `json:"id"`
BotID pgtype.UUID `json:"bot_id"`
ChannelType string `json:"channel_type"`
ChannelConfigID pgtype.UUID `json:"channel_config_id"`
ExternalConversationID string `json:"external_conversation_id"`
ExternalThreadID pgtype.Text `json:"external_thread_id"`
DefaultReplyTarget pgtype.Text `json:"default_reply_target"`
Metadata []byte `json:"metadata"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
type BotHistoryMessage struct {
ID pgtype.UUID `json:"id"`
BotID pgtype.UUID `json:"bot_id"`
RouteID pgtype.UUID `json:"route_id"`
SenderChannelIdentityID pgtype.UUID `json:"sender_channel_identity_id"`
SenderAccountUserID pgtype.UUID `json:"sender_account_user_id"`
ChannelType pgtype.Text `json:"channel_type"`
SourceMessageID pgtype.Text `json:"source_message_id"`
SourceReplyToMessageID pgtype.Text `json:"source_reply_to_message_id"`
Role string `json:"role"`
Content []byte `json:"content"`
Metadata []byte `json:"metadata"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
}
type BotMember struct {
BotID pgtype.UUID `json:"bot_id"`
UserID pgtype.UUID `json:"user_id"`
@@ -61,7 +90,7 @@ type BotPreauthKey struct {
type ChannelIdentity struct {
ID pgtype.UUID `json:"id"`
UserID pgtype.UUID `json:"user_id"`
Channel string `json:"channel"`
ChannelType string `json:"channel_type"`
ChannelSubjectID string `json:"channel_subject_id"`
DisplayName pgtype.Text `json:"display_name"`
Metadata []byte `json:"metadata"`
@@ -73,74 +102,13 @@ type ChannelIdentityBindCode struct {
ID pgtype.UUID `json:"id"`
Token string `json:"token"`
IssuedByUserID pgtype.UUID `json:"issued_by_user_id"`
Platform pgtype.Text `json:"platform"`
ChannelType pgtype.Text `json:"channel_type"`
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
UsedAt pgtype.Timestamptz `json:"used_at"`
UsedByChannelIdentityID pgtype.UUID `json:"used_by_channel_identity_id"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
}
type Chat struct {
ID pgtype.UUID `json:"id"`
BotID pgtype.UUID `json:"bot_id"`
Kind string `json:"kind"`
ParentChatID pgtype.UUID `json:"parent_chat_id"`
Title pgtype.Text `json:"title"`
CreatedByUserID pgtype.UUID `json:"created_by_user_id"`
Metadata []byte `json:"metadata"`
EnableChatMemory bool `json:"enable_chat_memory"`
EnablePrivateMemory bool `json:"enable_private_memory"`
EnablePublicMemory bool `json:"enable_public_memory"`
ModelID pgtype.Text `json:"model_id"`
SettingsMetadata []byte `json:"settings_metadata"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
type ChatChannelIdentityPresence struct {
ChatID pgtype.UUID `json:"chat_id"`
ChannelIdentityID pgtype.UUID `json:"channel_identity_id"`
FirstSeenAt pgtype.Timestamptz `json:"first_seen_at"`
LastSeenAt pgtype.Timestamptz `json:"last_seen_at"`
MessageCount int64 `json:"message_count"`
}
type ChatMessage struct {
ID pgtype.UUID `json:"id"`
ChatID pgtype.UUID `json:"chat_id"`
BotID pgtype.UUID `json:"bot_id"`
RouteID pgtype.UUID `json:"route_id"`
SenderChannelIdentityID pgtype.UUID `json:"sender_channel_identity_id"`
SenderUserID pgtype.UUID `json:"sender_user_id"`
Platform pgtype.Text `json:"platform"`
ExternalMessageID pgtype.Text `json:"external_message_id"`
Role string `json:"role"`
Content []byte `json:"content"`
Metadata []byte `json:"metadata"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
}
type ChatParticipant struct {
ChatID pgtype.UUID `json:"chat_id"`
UserID pgtype.UUID `json:"user_id"`
Role string `json:"role"`
JoinedAt pgtype.Timestamptz `json:"joined_at"`
}
type ChatRoute struct {
ID pgtype.UUID `json:"id"`
ChatID pgtype.UUID `json:"chat_id"`
BotID pgtype.UUID `json:"bot_id"`
Platform string `json:"platform"`
ChannelConfigID pgtype.UUID `json:"channel_config_id"`
ConversationID string `json:"conversation_id"`
ThreadID pgtype.Text `json:"thread_id"`
ReplyTarget pgtype.Text `json:"reply_target"`
Metadata []byte `json:"metadata"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
type Container struct {
ID pgtype.UUID `json:"id"`
BotID pgtype.UUID `json:"bot_id"`
@@ -277,10 +245,10 @@ type User struct {
}
type UserChannelBinding struct {
ID pgtype.UUID `json:"id"`
UserID pgtype.UUID `json:"user_id"`
Platform string `json:"platform"`
Config []byte `json:"config"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
ID pgtype.UUID `json:"id"`
UserID pgtype.UUID `json:"user_id"`
ChannelType string `json:"channel_type"`
Config []byte `json:"config"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}