feat(visitor): Implement visitor chat functionality and enhance customer service interactions

- Added a new visitor chat API endpoint (`/api/chat/visitor`) to allow unauthenticated users to engage in conversations without requiring customer data.
- Introduced a visitor context dependency to manage visitor interactions seamlessly.
- Enhanced the chat API to support explicit session termination and improved response handling for customer service interactions.
- Updated the database configuration to include Redis client support for caching visitor data.
- Added a new customer note repository to persist user notes independently of the L1 profile slots.

This update significantly improves the customer service experience by enabling visitor interactions and ensuring efficient data handling for both registered and unregistered users.
This commit is contained in:
2026-09-09 18:32:00 +08:00
parent ad930c26b1
commit b841f68295
98 changed files with 10682 additions and 630 deletions
@@ -0,0 +1,36 @@
-- 客服 Agent CS-C-11 / Wave 5 追加表(从 customer-service-agent 分支合并)
-- 用法:在 jinrong_agent 已建共用底座后执行;可重复执行前请先检查表是否已存在
-- 注意:不改动 risk_aml_list 等风控表(merger 以本仓库 02-mysql-agent专用.sql 为准)
USE jinrong_agent;
-- 会话归档摘要(会话结束 timeout / explicit / manual 时写入)
CREATE TABLE IF NOT EXISTS conversation_archive (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
session_id VARCHAR(64) NOT NULL COMMENT '关联 agent_session.session_id,一会话一归档',
trace_id VARCHAR(64) NOT NULL COMMENT '全链路追踪 ID',
agent_type ENUM('customer','advisor','analyst','risk') NOT NULL,
actor_id VARCHAR(64) NOT NULL COMMENT '操作者:客户=customer_id / 游客=VISITOR',
summary TEXT NOT NULL COMMENT 'DeepSeek 生成的会话摘要',
msg_count INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '消息条数(count agent_message)',
archive_reason ENUM('timeout','explicit','manual') NOT NULL COMMENT '归档触发原因',
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
UNIQUE KEY uk_session_id (session_id),
KEY idx_trace (trace_id),
KEY idx_actor (agent_type, actor_id, created_at)
) ENGINE=InnoDB COMMENT='【共用】会话归档摘要(CS-C-11,会话结束时生成)';
-- 客户显式备注(用户说「帮我记住…」,独立于 L1 画像槽位)
CREATE TABLE IF NOT EXISTS customer_notes (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
customer_id VARCHAR(64) NOT NULL COMMENT '客户ID(关联 customer_profile_l1.customer_id)',
session_id VARCHAR(64) NOT NULL COMMENT '备注生成的会话ID(关联 agent_session.session_id)',
trace_id VARCHAR(64) NOT NULL COMMENT '全链路追踪ID',
content VARCHAR(500) NOT NULL COMMENT 'LLM抽取后的纯净备注内容',
category VARCHAR(32) NULL COMMENT '可选分类:habit/preference/reminder/other',
source_text VARCHAR(800) NULL COMMENT '用户原话片段(审计用)',
is_active TINYINT(1) NOT NULL DEFAULT 1 COMMENT '1=有效 0=用户已删除(软删除)',
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
KEY idx_cid_active_time (customer_id, is_active, created_at),
KEY idx_trace (trace_id)
) ENGINE=InnoDB COMMENT='【客服】客户显式备注(用户主动要求记忆的自由文本,独立于 L1 画像)';