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:
@@ -1,8 +1,11 @@
|
||||
/**
|
||||
* 回归测试:admin-web 手动执行 App 类型必须与后端 /api/admin/ai/run/{app_type} 对齐。
|
||||
* 回归测试:admin-web app_type / cache_type 命名必须与后端
|
||||
* (CacheTypeEnum + dispatcher 写入 + chk_ai_cache_type CHECK 约束)对齐。
|
||||
*
|
||||
* 缓存类型仍使用 `*_analysis` / `*_consolidated`,但手动执行和 run log
|
||||
* 应使用 dispatcher 支持的 app_type,避免前端发出后端 400 的路径。
|
||||
* W1-AI-CLOSURE 组 1+5 命名统一后:
|
||||
* - cache_type 与 app_type 使用同一组应用名(与 prompt 文件名一致)
|
||||
* - 旧描述性后缀 'app6_note_analysis' / 'app7_customer_analysis' /
|
||||
* 'app8_clue_consolidated' / 'app8_consolidate' 已绝迹,前端不再保留。
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
@@ -10,34 +13,55 @@ import { RUN_APP_TYPES } from "../api/adminAI";
|
||||
import { CACHE_TYPE_OPTIONS, RUN_APP_TYPE_OPTIONS } from "../pages/AIOperations";
|
||||
import { RUN_LOG_APP_TYPE_OPTIONS } from "../pages/AIRunLogs";
|
||||
|
||||
describe("admin AI app_type 对齐", () => {
|
||||
it("手动执行类型使用后端支持的 app_type,而不是缓存类型", () => {
|
||||
const apiTypes = [...RUN_APP_TYPES];
|
||||
const runOptionValues = RUN_APP_TYPE_OPTIONS.map((item) => item.value);
|
||||
const NEW_APP_TYPES = [
|
||||
"app2_finance",
|
||||
"app2a_finance_area",
|
||||
"app3_clue",
|
||||
"app4_analysis",
|
||||
"app5_tactics",
|
||||
"app6_note",
|
||||
"app7_customer",
|
||||
"app8_consolidation",
|
||||
] as const;
|
||||
|
||||
for (const appType of ["app6_note", "app7_customer", "app8_consolidation"]) {
|
||||
expect(apiTypes).toContain(appType);
|
||||
const LEGACY_NAMES = [
|
||||
"app6_note_analysis",
|
||||
"app7_customer_analysis",
|
||||
"app8_clue_consolidated",
|
||||
"app8_consolidate",
|
||||
];
|
||||
|
||||
describe("admin AI app_type / cache_type 命名对齐", () => {
|
||||
it("RUN_APP_TYPES 与统一命名一致", () => {
|
||||
expect([...RUN_APP_TYPES]).toEqual(NEW_APP_TYPES);
|
||||
});
|
||||
|
||||
it("手动执行下拉只暴露统一命名(8 个),不含旧描述性后缀", () => {
|
||||
const runOptionValues = RUN_APP_TYPE_OPTIONS.map((item) => item.value);
|
||||
for (const appType of NEW_APP_TYPES) {
|
||||
expect(runOptionValues).toContain(appType);
|
||||
}
|
||||
|
||||
for (const cacheType of ["app6_note_analysis", "app7_customer_analysis", "app8_clue_consolidated"]) {
|
||||
expect(runOptionValues).not.toContain(cacheType);
|
||||
for (const legacy of LEGACY_NAMES) {
|
||||
expect(runOptionValues).not.toContain(legacy);
|
||||
}
|
||||
});
|
||||
|
||||
it("缓存失效继续使用 cache_type,避免破坏已有缓存管理", () => {
|
||||
it("缓存失效下拉与统一命名对齐,不含旧描述性后缀", () => {
|
||||
const cacheOptionValues = CACHE_TYPE_OPTIONS.map((item) => item.value);
|
||||
|
||||
expect(cacheOptionValues).toContain("app6_note_analysis");
|
||||
expect(cacheOptionValues).toContain("app7_customer_analysis");
|
||||
expect(cacheOptionValues).toContain("app8_clue_consolidated");
|
||||
for (const cacheType of NEW_APP_TYPES) {
|
||||
expect(cacheOptionValues).toContain(cacheType);
|
||||
}
|
||||
for (const legacy of LEGACY_NAMES) {
|
||||
expect(cacheOptionValues).not.toContain(legacy);
|
||||
}
|
||||
});
|
||||
|
||||
it("调用记录筛选包含真实写入 ai_run_logs 的 app_type", () => {
|
||||
it("调用记录筛选包含 chat + 8 个写缓存应用,不含旧 'app8_consolidate'", () => {
|
||||
const runLogOptionValues = RUN_LOG_APP_TYPE_OPTIONS.map((item) => item.value);
|
||||
|
||||
expect(runLogOptionValues).toContain("app6_note");
|
||||
expect(runLogOptionValues).toContain("app7_customer");
|
||||
expect(runLogOptionValues).toContain("app8_consolidate");
|
||||
expect(runLogOptionValues).toContain("app1_chat");
|
||||
for (const appType of NEW_APP_TYPES) {
|
||||
expect(runLogOptionValues).toContain(appType);
|
||||
}
|
||||
expect(runLogOptionValues).not.toContain("app8_consolidate");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -33,13 +33,17 @@ const EVENT_TYPE_OPTIONS = [
|
||||
const { TextArea } = Input;
|
||||
const { Title } = Typography;
|
||||
|
||||
// W1-AI-CLOSURE 组 1+5:cache_type 命名与 prompt 文件名 + 数据库 chk_ai_cache_type
|
||||
// 约束完全对齐(旧描述性后缀 _analysis / _consolidated 已废弃)。
|
||||
export const CACHE_TYPE_OPTIONS = [
|
||||
{ label: "App2 财务洞察(全域)", value: "app2_finance" },
|
||||
{ label: "App2a 财务洞察(区域)", value: "app2a_finance_area" },
|
||||
{ label: "App3 维客线索", value: "app3_clue" },
|
||||
{ label: "App4 关系分析", value: "app4_analysis" },
|
||||
{ label: "App5 话术参考", value: "app5_tactics" },
|
||||
{ label: "App6 备注分析", value: "app6_note_analysis" },
|
||||
{ label: "App7 客户分析", value: "app7_customer_analysis" },
|
||||
{ label: "App8 线索整理", value: "app8_clue_consolidated" },
|
||||
{ label: "App6 备注分析", value: "app6_note" },
|
||||
{ label: "App7 客户分析", value: "app7_customer" },
|
||||
{ label: "App8 线索整理", value: "app8_consolidation" },
|
||||
];
|
||||
|
||||
export const RUN_APP_TYPE_OPTIONS: { label: string; value: AppType }[] = [
|
||||
|
||||
@@ -253,8 +253,10 @@ const AIRunLogs: React.FC = () => {
|
||||
|
||||
export default AIRunLogs;
|
||||
|
||||
// W1-AI-CLOSURE 组 1+5:ai_run_logs.app_type 命名统一(数据库已 UPDATE);
|
||||
// 旧 'app8_consolidate' 已不再存在,从下拉移除。
|
||||
export const RUN_LOG_APP_TYPE_OPTIONS = [
|
||||
"app1_chat", "app2_finance", "app2a_finance_area", "app3_clue",
|
||||
"app4_analysis", "app5_tactics", "app6_note", "app7_customer",
|
||||
"app8_consolidate", "app8_consolidation",
|
||||
"app8_consolidation",
|
||||
].map((v) => ({ label: v, value: v }));
|
||||
|
||||
Reference in New Issue
Block a user