feat(ai): W1-AI-CLOSURE 超级 Sprint — 9 APP 全链路收口 + chat 上下文真激活
Phase 2.3 chat 上下文捕获链路从未真正激活到完整工作: - 14 处 ai-float-button 补 sourcePage,chat.ts 三分支同步设 pageFilters.contextId - 后端 page_context 4 层 BUG 修(列名错位 + RLS site_id 未重设) - xcx_chat filters.pop 破坏 body.page_context 引用 — dict() 浅拷贝隔离 - chat 流式 markdown 实时解析(表格/标题/列表/加粗 + KPI 富卡) - reference_card KPI 富卡接入 SSE 路径,db 真写入 - 维客线索 source 显示规则:AI 来源用机器人 icon 替代长文字 数据库: - public.member_retention_clue 加 emoji + runtime_mode + sandbox_instance_id - biz.ai_run_logs 加 assistant_id + 复合索引 - chk_ai_cache_type CHECK 约束 8 类应用名 - cache_type / app_type 命名统一(app6_note / app7_customer / app8_consolidation) - 历史 emoji 抽取脚本 44/44 成功 后端 silent failure 修: - cleanup_service WHERE app_type → cache_type(90 天清理 + 20K 上限重新生效) - _build_ai_insight 字段错位修复(app4 → app7 + 字段对齐 prompt schema) - task_manager talkingPoints 改 app5_tactics + tactics 字段 - task_manager aiSuggestion 改取 one_line_summary - cache_service.CACHE_EXPIRY_DAYS 加 app2a_finance_area - WS /ws/ai-cache 加 token + JWT + site_id 校验(P0 信息泄露漏洞) - internal_ai token 改 hmac.compare_digest 工具/文档: - main.py 加 RotatingFileHandler logs/backend.log + uvicorn /health 过滤 - 新建 utils/clue_category.py(VI 6 类配色 + emoji fallback + source 显示规则) - 新建 utils/markdown.ts(轻量 md 转 rich-text 解析 + streaming 容错) - audit + 数据库变更说明 + backlog §七 #14 收口 + #15-#38 残余子任务 - backlog 追加 §十一 App1 参数/MCP/沙箱审计 + §十二 百炼/SQL MCP 主任务线 实地 MCP 走查:14 入口数据层 + 5 代表入口 sourcePage 注入 + customer-detail 全模块 + chat md 渲染 + reference_card 富卡 都已验证。9 项预先 BUG/UX 登记 §七 #29-#38 后续修复。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -192,6 +192,13 @@ def _text_customer_detail(
|
||||
try:
|
||||
etl_conn = get_etl_readonly_connection(site_id)
|
||||
with etl_conn.cursor() as cur:
|
||||
# W1-AI-CLOSURE 复盘修正:get_etl_readonly_connection 在 SET LOCAL 后
|
||||
# commit(LOCAL 失效),后续 cursor 进入新事务,RLS 视图 current_setting
|
||||
# ('app.current_site_id') 拿到空串导致 bigint 转换失败。每次 cursor 必须
|
||||
# 重新 SET 当前事务的 GUC(对齐 member_data.py / assistant_data.py 模式)。
|
||||
cur.execute(
|
||||
"SET LOCAL app.current_site_id = %s", (str(site_id),)
|
||||
)
|
||||
cur.execute(
|
||||
"SET LOCAL statement_timeout = %s",
|
||||
(f"{FDW_QUERY_TIMEOUT_SEC * 1000}",),
|
||||
@@ -210,21 +217,34 @@ def _text_customer_detail(
|
||||
nickname = m_row[0] if m_row else f"ID:{member_id}"
|
||||
|
||||
# 最近 5 条消费
|
||||
# W1-AI-CLOSURE 复盘修正:列名错位 — v_dwd_settlement_head 实际列是
|
||||
# pay_time / settle_name(无 settle_date / room_name);items_sum 按
|
||||
# DWD-DOC 强制规则 #1 用合成表达式(consume_money 禁止直接计算)。
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT settle_date, items_sum, room_name
|
||||
SELECT
|
||||
pay_time,
|
||||
(COALESCE(table_charge_money, 0)
|
||||
+ COALESCE(goods_money, 0)
|
||||
+ COALESCE(assistant_pd_money, 0)
|
||||
+ COALESCE(assistant_cx_money, 0)
|
||||
+ COALESCE(electricity_money, 0)) AS items_sum,
|
||||
settle_name
|
||||
FROM app.v_dwd_settlement_head
|
||||
WHERE member_id = %s AND settle_type IN (1, 3)
|
||||
ORDER BY settle_date DESC LIMIT 5
|
||||
ORDER BY pay_time DESC LIMIT 5
|
||||
""",
|
||||
(member_id,),
|
||||
)
|
||||
recent = cur.fetchall()
|
||||
|
||||
# 余额
|
||||
# W1-AI-CLOSURE 复盘修正:列名 balance_amount 不存在,实际列是
|
||||
# cash_card_balance / gift_card_balance / total_card_balance;
|
||||
# total_card_balance 是合计储值(对齐 customer_service.balance 字段)。
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT balance_amount
|
||||
SELECT total_card_balance
|
||||
FROM app.v_dws_member_consumption_summary
|
||||
WHERE member_id = %s LIMIT 1
|
||||
""",
|
||||
@@ -233,14 +253,15 @@ def _text_customer_detail(
|
||||
bal_row = cur.fetchone()
|
||||
etl_conn.commit()
|
||||
|
||||
# 维客线索
|
||||
# 维客线索(W1-AI-CLOSURE 复盘修正:列名 created_at 不存在,实际是 recorded_at;
|
||||
# 表加 schema 前缀 public 防 search_path 漂移;补 is_hidden 过滤)
|
||||
biz_conn = get_connection()
|
||||
with biz_conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT summary FROM member_retention_clue
|
||||
WHERE member_id = %s AND site_id = %s
|
||||
ORDER BY created_at DESC LIMIT 5
|
||||
SELECT summary FROM public.member_retention_clue
|
||||
WHERE member_id = %s AND site_id = %s AND is_hidden = false
|
||||
ORDER BY recorded_at DESC LIMIT 5
|
||||
""",
|
||||
(member_id, site_id),
|
||||
)
|
||||
@@ -281,6 +302,11 @@ def _text_coach_detail(
|
||||
try:
|
||||
etl_conn = get_etl_readonly_connection(site_id)
|
||||
with etl_conn.cursor() as cur:
|
||||
# W1-AI-CLOSURE 复盘修正:get_etl_readonly_connection 在 SET LOCAL 后
|
||||
# commit(LOCAL 失效),后续 cursor 在新事务中 RLS 视图查不到 site_id。
|
||||
cur.execute(
|
||||
"SET LOCAL app.current_site_id = %s", (str(site_id),)
|
||||
)
|
||||
cur.execute(
|
||||
"SET LOCAL statement_timeout = %s",
|
||||
(f"{FDW_QUERY_TIMEOUT_SEC * 1000}",),
|
||||
@@ -348,6 +374,11 @@ def _text_board_finance(
|
||||
try:
|
||||
etl_conn = get_etl_readonly_connection(site_id)
|
||||
with etl_conn.cursor() as cur:
|
||||
# W1-AI-CLOSURE 复盘修正:get_etl_readonly_connection 在 SET LOCAL 后
|
||||
# commit(LOCAL 失效),后续 cursor 在新事务中 RLS 视图查不到 site_id。
|
||||
cur.execute(
|
||||
"SET LOCAL app.current_site_id = %s", (str(site_id),)
|
||||
)
|
||||
cur.execute(
|
||||
"SET LOCAL statement_timeout = %s",
|
||||
(f"{FDW_QUERY_TIMEOUT_SEC * 1000}",),
|
||||
@@ -399,6 +430,11 @@ def _text_board_customer(
|
||||
try:
|
||||
etl_conn = get_etl_readonly_connection(site_id)
|
||||
with etl_conn.cursor() as cur:
|
||||
# W1-AI-CLOSURE 复盘修正:get_etl_readonly_connection 在 SET LOCAL 后
|
||||
# commit(LOCAL 失效),后续 cursor 在新事务中 RLS 视图查不到 site_id。
|
||||
cur.execute(
|
||||
"SET LOCAL app.current_site_id = %s", (str(site_id),)
|
||||
)
|
||||
cur.execute(
|
||||
"SET LOCAL statement_timeout = %s",
|
||||
(f"{FDW_QUERY_TIMEOUT_SEC * 1000}",),
|
||||
@@ -456,6 +492,11 @@ def _text_board_coach(
|
||||
try:
|
||||
etl_conn = get_etl_readonly_connection(site_id)
|
||||
with etl_conn.cursor() as cur:
|
||||
# W1-AI-CLOSURE 复盘修正:get_etl_readonly_connection 在 SET LOCAL 后
|
||||
# commit(LOCAL 失效),后续 cursor 在新事务中 RLS 视图查不到 site_id。
|
||||
cur.execute(
|
||||
"SET LOCAL app.current_site_id = %s", (str(site_id),)
|
||||
)
|
||||
cur.execute(
|
||||
"SET LOCAL statement_timeout = %s",
|
||||
(f"{FDW_QUERY_TIMEOUT_SEC * 1000}",),
|
||||
@@ -515,6 +556,11 @@ def _text_performance(
|
||||
try:
|
||||
etl_conn = get_etl_readonly_connection(site_id)
|
||||
with etl_conn.cursor() as cur:
|
||||
# W1-AI-CLOSURE 复盘修正:get_etl_readonly_connection 在 SET LOCAL 后
|
||||
# commit(LOCAL 失效),后续 cursor 在新事务中 RLS 视图查不到 site_id。
|
||||
cur.execute(
|
||||
"SET LOCAL app.current_site_id = %s", (str(site_id),)
|
||||
)
|
||||
cur.execute(
|
||||
"SET LOCAL statement_timeout = %s",
|
||||
(f"{FDW_QUERY_TIMEOUT_SEC * 1000}",),
|
||||
@@ -599,6 +645,11 @@ def _text_customer_service_records(
|
||||
try:
|
||||
etl_conn = get_etl_readonly_connection(site_id)
|
||||
with etl_conn.cursor() as cur:
|
||||
# W1-AI-CLOSURE 复盘修正:get_etl_readonly_connection 在 SET LOCAL 后
|
||||
# commit(LOCAL 失效),后续 cursor 在新事务中 RLS 视图查不到 site_id。
|
||||
cur.execute(
|
||||
"SET LOCAL app.current_site_id = %s", (str(site_id),)
|
||||
)
|
||||
cur.execute(
|
||||
"SET LOCAL statement_timeout = %s",
|
||||
(f"{FDW_QUERY_TIMEOUT_SEC * 1000}",),
|
||||
|
||||
Reference in New Issue
Block a user