Files
Neo-ZQYY/apps/backend/app/schemas/member_retention_clue.py
Neo 2dfc926f96 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>
2026-05-06 16:39:07 +08:00

59 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
维客线索相关 Pydantic 模型。
大类枚举(6 类,与数据库 chk_retention_clue_category 约束 + ai/schemas
App3CategoryEnum / App6CategoryEnum 完全对齐):
客户基础、消费习惯、玩法偏好、促销偏好、社交关系、重要反馈
"""
from datetime import datetime
from enum import Enum
from typing import Optional
from pydantic import BaseModel, Field
class ClueCategory(str, Enum):
"""维客线索大类枚举(W1-AI-CLOSURE 组 5:'客户基础信息' 字面量纠正为 '客户基础',
旧值与数据库 CHECK 约束不一致,POST /api/retention-clue 写库会失败)。"""
BASIC_INFO = "客户基础"
CONSUMPTION = "消费习惯"
PLAY_PREF = "玩法偏好"
PROMO_PREF = "促销偏好"
SOCIAL = "社交关系"
FEEDBACK = "重要反馈"
class ClueSource(str, Enum):
"""维客线索来源枚举"""
MANUAL = "manual" # 助教手动录入
AI_CONSUMPTION = "ai_consumption" # 应用 3消费分析自动生成
AI_NOTE = "ai_note" # 应用 6备注分析自动提取
class RetentionClueSubmit(BaseModel):
"""提交维客线索请求。"""
member_id: int = Field(..., gt=0, description="会员 ID")
category: ClueCategory = Field(..., description="线索大类")
summary: str = Field(..., min_length=1, max_length=200, description="摘要:重点信息")
detail: Optional[str] = Field(None, max_length=2000, description="详情:分析及扩展说明,可为空")
recorded_by_assistant_id: int = Field(..., gt=0, description="记录助教 ID")
recorded_by_name: str = Field(..., min_length=1, max_length=50, description="记录助教姓名")
site_id: int = Field(..., gt=0, description="门店 ID")
source: ClueSource = Field(default=ClueSource.MANUAL, description="线索来源")
class RetentionClueOut(BaseModel):
"""维客线索返回模型。"""
id: int
member_id: int
category: ClueCategory
summary: str
detail: Optional[str]
recorded_by_assistant_id: Optional[int]
recorded_by_name: Optional[str]
recorded_at: datetime
site_id: int
source: ClueSource = ClueSource.MANUAL