feat: IM平台列 + deviceID标识 + 会话持久化完善
- agent-96: chat_messages 加 platform 列(迁移0004) + IM主人私聊落主会话web(带platform) + 前端按平台过滤契约 + message_persisted 带 platform(复用 BroadcastPersisted) - agent-97: chat_messages 加 device_id 列(迁移0005) + history.Message.DeviceID + Web发消息带deviceId(localStorage getClientId) + IM persistToMain 带 deviceID + 前端气泡展示 SourceLabel + 修主会话基础2个bug(fn scanMessage语法/DDL缺列) - design/16 §4.4(平台) + §4.5(deviceID) 已入档 - 实机: POST /chat 带 deviceId 读回 user/assistant 均带 deviceId+platform; 后端 build/vet/test 绿 + 前端 build 绿 - 红线: 身份靠 actor 元数据; 禁止 shell 读 .env(JWT冒烟由主会话跑)
This commit is contained in:
1 parent
1bf60c1ae4
commit
37e98ec584
26 files changed
+828
-116
No files matched your search
@@ -0,0 +1,25 @@
|
||||
-- 0004_chat_history_platform: rolls back the platform column added by the up
|
||||
-- migration. SQLite's ALTER DROP COLUMN is version-dependent (3.35+), so the column
|
||||
-- is removed by recreating the table without it — universally safe and lossless
|
||||
-- (the platform tag is not needed once the column is gone).
|
||||
|
||||
CREATE TABLE chat_messages_new (
|
||||
id TEXT PRIMARY KEY,
|
||||
session_id TEXT NOT NULL,
|
||||
role TEXT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
mode TEXT,
|
||||
mood TEXT,
|
||||
image TEXT,
|
||||
thinking TEXT,
|
||||
created_at INTEGER NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO chat_messages_new (id, session_id, role, content, mode, mood, image, thinking, created_at)
|
||||
SELECT id, session_id, role, content, mode, mood, image, thinking, created_at FROM chat_messages;
|
||||
|
||||
DROP TABLE chat_messages;
|
||||
ALTER TABLE chat_messages_new RENAME TO chat_messages;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_chat_msgs_session_created
|
||||
ON chat_messages (session_id, created_at DESC);
|
||||
@@ -0,0 +1,13 @@
|
||||
-- 0004_chat_history_platform: tag every chat message with its source platform
|
||||
-- (DevDocs/design/16 §4.4). The Web main session is shared across platforms: the
|
||||
-- Web client renders the full session, while each IM adapter filters to its own
|
||||
-- platform lane. Messages that originate on the Web carry 'web'; IM owner-private
|
||||
-- messages carry the channel platform (e.g. 'weixin-ilink', 'qq-obv11', 'telegram').
|
||||
--
|
||||
-- The 0003 chat_messages table already exists at this point, so ALTER ADD COLUMN is
|
||||
-- the correct, non-destructive step. The canonical schema (including this column) is
|
||||
-- also re-issued idempotently by internal/runtime/history.NewStore so a fresh
|
||||
-- in-memory store used by tests stays self-contained; the migration is the
|
||||
-- authoritative path for an existing database.
|
||||
|
||||
ALTER TABLE chat_messages ADD COLUMN platform TEXT NOT NULL DEFAULT 'web';
|
||||
@@ -0,0 +1,4 @@
|
||||
-- 0005_chat_device down: drop the device_id column.
|
||||
-- SQLite DROP COLUMN is supported on modern versions; rebuild safely when needed.
|
||||
|
||||
ALTER TABLE chat_messages DROP COLUMN device_id;
|
||||
@@ -0,0 +1,10 @@
|
||||
-- 0005_chat_device: tag every chat message with a short deviceID/client identifier
|
||||
-- (DevDocs/design/16 §4.5). deviceID is the concrete client (browser/app/IM channel
|
||||
-- binding) that produced the message, complementing `platform` which only names
|
||||
-- the platform. It lets the agent know exactly HOW the owner is chatting (e.g.
|
||||
-- "web:chrome:a1b2c3" for a browser, "weixin-ilink:conf0:wx_uid_123" for IM).
|
||||
--
|
||||
-- The 0004 chat_messages table already exists at this point, so ALTER ADD COLUMN is
|
||||
-- the correct, non-destructive step.
|
||||
|
||||
ALTER TABLE chat_messages ADD COLUMN device_id TEXT NOT NULL DEFAULT '';
|
||||
Reference in new issue
Block a user