mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
refactor(core): restructure conversation/channel/message domains and modernize deployment
- Replace chat package with conversation flow architecture - Add channel identity avatar support (migration 0002) - Refactor channel adapters, identities, and message routing - Update frontend: simplify composables, modernize UI components - Improve Docker builds with cache mounts and version metadata - Optimize healthchecks and simplify service dependencies
This commit is contained in:
@@ -70,7 +70,7 @@ CREATE TABLE IF NOT EXISTS llm_providers (
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
CONSTRAINT llm_providers_name_unique UNIQUE (name),
|
||||
CONSTRAINT llm_providers_client_type_check CHECK (client_type IN ('openai', 'openai-compat', 'anthropic', 'google', 'ollama'))
|
||||
CONSTRAINT llm_providers_client_type_check CHECK (client_type IN ('openai', 'openai-compat', 'anthropic', 'google', 'azure', 'bedrock', 'mistral', 'xai', 'ollama', 'dashscope'))
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS models (
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
-- 0002_channel_identity_avatar (down)
|
||||
ALTER TABLE channel_identities DROP COLUMN IF EXISTS avatar_url;
|
||||
@@ -0,0 +1,3 @@
|
||||
-- 0002_channel_identity_avatar
|
||||
-- Add avatar_url column to channel_identities for sender profile display.
|
||||
ALTER TABLE channel_identities ADD COLUMN IF NOT EXISTS avatar_url TEXT;
|
||||
@@ -1,37 +1,38 @@
|
||||
-- name: CreateChannelIdentity :one
|
||||
INSERT INTO channel_identities (user_id, channel_type, channel_subject_id, display_name, metadata)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING id, user_id, channel_type, channel_subject_id, display_name, metadata, created_at, updated_at;
|
||||
INSERT INTO channel_identities (user_id, channel_type, channel_subject_id, display_name, avatar_url, metadata)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
RETURNING id, user_id, channel_type, channel_subject_id, display_name, avatar_url, metadata, created_at, updated_at;
|
||||
|
||||
-- name: GetChannelIdentityByID :one
|
||||
SELECT id, user_id, channel_type, channel_subject_id, display_name, metadata, created_at, updated_at
|
||||
SELECT id, user_id, channel_type, channel_subject_id, display_name, avatar_url, metadata, created_at, updated_at
|
||||
FROM channel_identities
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: GetChannelIdentityByIDForUpdate :one
|
||||
SELECT id, user_id, channel_type, channel_subject_id, display_name, metadata, created_at, updated_at
|
||||
SELECT id, user_id, channel_type, channel_subject_id, display_name, avatar_url, metadata, created_at, updated_at
|
||||
FROM channel_identities
|
||||
WHERE id = $1
|
||||
FOR UPDATE;
|
||||
|
||||
-- name: GetChannelIdentityByChannelSubject :one
|
||||
SELECT id, user_id, channel_type, channel_subject_id, display_name, metadata, created_at, updated_at
|
||||
SELECT id, user_id, channel_type, channel_subject_id, display_name, avatar_url, metadata, created_at, updated_at
|
||||
FROM channel_identities
|
||||
WHERE channel_type = $1 AND channel_subject_id = $2;
|
||||
|
||||
-- name: UpsertChannelIdentityByChannelSubject :one
|
||||
INSERT INTO channel_identities (user_id, channel_type, channel_subject_id, display_name, metadata)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
INSERT INTO channel_identities (user_id, channel_type, channel_subject_id, display_name, avatar_url, metadata)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
ON CONFLICT (channel_type, channel_subject_id)
|
||||
DO UPDATE SET
|
||||
display_name = COALESCE(NULLIF(EXCLUDED.display_name, ''), channel_identities.display_name),
|
||||
avatar_url = COALESCE(NULLIF(EXCLUDED.avatar_url, ''), channel_identities.avatar_url),
|
||||
metadata = EXCLUDED.metadata,
|
||||
user_id = COALESCE(channel_identities.user_id, EXCLUDED.user_id),
|
||||
updated_at = now()
|
||||
RETURNING id, user_id, channel_type, channel_subject_id, display_name, metadata, created_at, updated_at;
|
||||
RETURNING id, user_id, channel_type, channel_subject_id, display_name, avatar_url, metadata, created_at, updated_at;
|
||||
|
||||
-- name: ListChannelIdentitiesByUserID :many
|
||||
SELECT id, user_id, channel_type, channel_subject_id, display_name, metadata, created_at, updated_at
|
||||
SELECT id, user_id, channel_type, channel_subject_id, display_name, avatar_url, metadata, created_at, updated_at
|
||||
FROM channel_identities
|
||||
WHERE user_id = $1
|
||||
ORDER BY created_at DESC;
|
||||
@@ -40,10 +41,10 @@ ORDER BY created_at DESC;
|
||||
UPDATE channel_identities
|
||||
SET user_id = $2, updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, user_id, channel_type, channel_subject_id, display_name, metadata, created_at, updated_at;
|
||||
RETURNING id, user_id, channel_type, channel_subject_id, display_name, avatar_url, metadata, created_at, updated_at;
|
||||
|
||||
-- name: ClearChannelIdentityLinkedUser :one
|
||||
UPDATE channel_identities
|
||||
SET user_id = NULL, updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, user_id, channel_type, channel_subject_id, display_name, metadata, created_at, updated_at;
|
||||
RETURNING id, user_id, channel_type, channel_subject_id, display_name, avatar_url, metadata, created_at, updated_at;
|
||||
|
||||
+74
-62
@@ -39,78 +39,90 @@ RETURNING
|
||||
|
||||
-- name: ListMessages :many
|
||||
SELECT
|
||||
id,
|
||||
bot_id,
|
||||
route_id,
|
||||
sender_channel_identity_id,
|
||||
sender_account_user_id AS sender_user_id,
|
||||
channel_type AS platform,
|
||||
source_message_id AS external_message_id,
|
||||
source_reply_to_message_id,
|
||||
role,
|
||||
content,
|
||||
metadata,
|
||||
created_at
|
||||
FROM bot_history_messages
|
||||
WHERE bot_id = sqlc.arg(bot_id)
|
||||
ORDER BY created_at ASC;
|
||||
m.id,
|
||||
m.bot_id,
|
||||
m.route_id,
|
||||
m.sender_channel_identity_id,
|
||||
m.sender_account_user_id AS sender_user_id,
|
||||
m.channel_type AS platform,
|
||||
m.source_message_id AS external_message_id,
|
||||
m.source_reply_to_message_id,
|
||||
m.role,
|
||||
m.content,
|
||||
m.metadata,
|
||||
m.created_at,
|
||||
ci.display_name AS sender_display_name,
|
||||
ci.avatar_url AS sender_avatar_url
|
||||
FROM bot_history_messages m
|
||||
LEFT JOIN channel_identities ci ON ci.id = m.sender_channel_identity_id
|
||||
WHERE m.bot_id = sqlc.arg(bot_id)
|
||||
ORDER BY m.created_at ASC;
|
||||
|
||||
-- name: ListMessagesSince :many
|
||||
SELECT
|
||||
id,
|
||||
bot_id,
|
||||
route_id,
|
||||
sender_channel_identity_id,
|
||||
sender_account_user_id AS sender_user_id,
|
||||
channel_type AS platform,
|
||||
source_message_id AS external_message_id,
|
||||
source_reply_to_message_id,
|
||||
role,
|
||||
content,
|
||||
metadata,
|
||||
created_at
|
||||
FROM bot_history_messages
|
||||
WHERE bot_id = sqlc.arg(bot_id)
|
||||
AND created_at >= sqlc.arg(created_at)
|
||||
ORDER BY created_at ASC;
|
||||
m.id,
|
||||
m.bot_id,
|
||||
m.route_id,
|
||||
m.sender_channel_identity_id,
|
||||
m.sender_account_user_id AS sender_user_id,
|
||||
m.channel_type AS platform,
|
||||
m.source_message_id AS external_message_id,
|
||||
m.source_reply_to_message_id,
|
||||
m.role,
|
||||
m.content,
|
||||
m.metadata,
|
||||
m.created_at,
|
||||
ci.display_name AS sender_display_name,
|
||||
ci.avatar_url AS sender_avatar_url
|
||||
FROM bot_history_messages m
|
||||
LEFT JOIN channel_identities ci ON ci.id = m.sender_channel_identity_id
|
||||
WHERE m.bot_id = sqlc.arg(bot_id)
|
||||
AND m.created_at >= sqlc.arg(created_at)
|
||||
ORDER BY m.created_at ASC;
|
||||
|
||||
-- name: ListMessagesBefore :many
|
||||
SELECT
|
||||
id,
|
||||
bot_id,
|
||||
route_id,
|
||||
sender_channel_identity_id,
|
||||
sender_account_user_id AS sender_user_id,
|
||||
channel_type AS platform,
|
||||
source_message_id AS external_message_id,
|
||||
source_reply_to_message_id,
|
||||
role,
|
||||
content,
|
||||
metadata,
|
||||
created_at
|
||||
FROM bot_history_messages
|
||||
WHERE bot_id = sqlc.arg(bot_id)
|
||||
AND created_at < sqlc.arg(created_at)
|
||||
ORDER BY created_at DESC
|
||||
m.id,
|
||||
m.bot_id,
|
||||
m.route_id,
|
||||
m.sender_channel_identity_id,
|
||||
m.sender_account_user_id AS sender_user_id,
|
||||
m.channel_type AS platform,
|
||||
m.source_message_id AS external_message_id,
|
||||
m.source_reply_to_message_id,
|
||||
m.role,
|
||||
m.content,
|
||||
m.metadata,
|
||||
m.created_at,
|
||||
ci.display_name AS sender_display_name,
|
||||
ci.avatar_url AS sender_avatar_url
|
||||
FROM bot_history_messages m
|
||||
LEFT JOIN channel_identities ci ON ci.id = m.sender_channel_identity_id
|
||||
WHERE m.bot_id = sqlc.arg(bot_id)
|
||||
AND m.created_at < sqlc.arg(created_at)
|
||||
ORDER BY m.created_at DESC
|
||||
LIMIT sqlc.arg(max_count);
|
||||
|
||||
-- name: ListMessagesLatest :many
|
||||
SELECT
|
||||
id,
|
||||
bot_id,
|
||||
route_id,
|
||||
sender_channel_identity_id,
|
||||
sender_account_user_id AS sender_user_id,
|
||||
channel_type AS platform,
|
||||
source_message_id AS external_message_id,
|
||||
source_reply_to_message_id,
|
||||
role,
|
||||
content,
|
||||
metadata,
|
||||
created_at
|
||||
FROM bot_history_messages
|
||||
WHERE bot_id = sqlc.arg(bot_id)
|
||||
ORDER BY created_at DESC
|
||||
m.id,
|
||||
m.bot_id,
|
||||
m.route_id,
|
||||
m.sender_channel_identity_id,
|
||||
m.sender_account_user_id AS sender_user_id,
|
||||
m.channel_type AS platform,
|
||||
m.source_message_id AS external_message_id,
|
||||
m.source_reply_to_message_id,
|
||||
m.role,
|
||||
m.content,
|
||||
m.metadata,
|
||||
m.created_at,
|
||||
ci.display_name AS sender_display_name,
|
||||
ci.avatar_url AS sender_avatar_url
|
||||
FROM bot_history_messages m
|
||||
LEFT JOIN channel_identities ci ON ci.id = m.sender_channel_identity_id
|
||||
WHERE m.bot_id = sqlc.arg(bot_id)
|
||||
ORDER BY m.created_at DESC
|
||||
LIMIT sqlc.arg(max_count);
|
||||
|
||||
-- name: DeleteMessagesByBot :exec
|
||||
|
||||
Reference in New Issue
Block a user