Files
Simon 449c6d4875 feat: 2026-07-12~13 全量更新 - AI对话链路改造+H5 v4/v5+坐席端v5+上下文感知诊断+知识库迭代3
## H5 员工端 v4 (2026-07-13 00:48 已部署)
- 人工按钮三态文案统一为"人工坐席"
- 按钮位置移至发送键和语音按钮上方(垂直堆叠)
- 点按钮直接调 store.shakeAgent(),删除 CallAgentModal 弹窗动画
- 截图快捷键提示改为"截图->粘贴:Alt+Shift+A-Ctrl+V ---> Ctrl+V"
- 移动端隐藏截图提示(CSS 媒体查询)
- AI转人工提示改为"已为您呼叫人工坐席,请稍等!"
- 坐席接入提示改为"坐席正在查看您的信息,请等待处理回复!"
- 删除"摇铃呼叫坐席"入口和文案
- 删除孤儿组件 MessageList.vue + shake 动画 CSS

## H5 员工端 v5 (2026-07-13 02:08 已部署)
- RightPanel v2.1:删除"软件安装"和"资源权限"标签页
- 移除标签栏,智能推荐(DynamicRecommend)直接展示
- 删除 SoftwareDownloads/ApprovalLinks 引用和相关 CSS

## AI 对话链路全栈改造 Phase 1-6 (已部署)
- Phase 1: Dify JSON输出 + 后端blocking解析 + 双WS推送 + 错误降级
- Phase 2: 关键词收窄(~25强意图词) + 两级分类Prompt + 删除前端checkApprovalIntent
- Phase 3: WS扩展(ai_thinking+dynamic_recommend) + ai_structured气泡 + RightPanel v2 + 选项回传
- Phase 4: VisionService接入 + 图片消息融合(5秒窗口) + 降级策略
- Phase 5: 坐席端ai_thinking指示器 + ai_structured/byod_card渲染 + handleNewMessage修复
- Phase 6: diagnosis_stage(6值) + response_time_ms计时 + 慢响应告警(>10s)

## 坐席端 v5 (2026-07-13 01:38 已部署)
- ai_structured/byod_card 只读渲染
- AI思考指示器 UI
- handleNewMessage 透传 msg_type/extra_data 修复
- 布局优化v2.0: QuickReplyBar L1+L2悬浮 + ReplyBox左右分区 + 右栏260/560px切换
- 键盘快捷键v2.3: 纯数字路由 + ESC分层撤销 + Shift+Space用event.code

## 上下文感知智能诊断闭环 (2026-07-12 已部署)
- 三层诊断(API→Script→AI) + 三段排队(VIP→info_locked→not locked)
- 答题插队 + 五场景关闭
- 迁移052(6表+6列) + queue_service + quiz_service + closing_service
- H5前端: QueueWaiting + RightPanel双Tab + InputBar三态 + ResolveConfirmCard
- 坐席前端: pending_close结单流程 + 信息锁定(Dify步骤完成+有效回答率≥70%)

## 知识库迭代3 (2026-07-12 已部署)
- 分诊交互(H5+坐席+Dify独立应用)
- 拓扑预览(ECharts只读)
- 代答排除(4种匹配器: keyword/regex/intent/category)
- 迁移051 + 44文件43测试通过

## 后端变更
- 6个Python文件改造(h5_ai_task.py/h5.py/ai_service.py/closing_service.py等)
- funny_phrase_service.py: shake/connected/keyword 默认文案更新
- session_service.py: 企微消息文案同步
- 新增: queue.py/quiz.py/triage.py/exclusion_rules.py 等API端点
- 新增: diagnostic.py/quiz.py/triage_session.py 等模型
- 新增: closing_service/queue_service/quiz_service/triage_service 等服务

## 文档更新
- CHANGELOG.md: 新增 [未发布] 区全部变更记录
- 项目管理主文档 v2.5: 新增v0.7.3版本 + 已完成看板 + 最近搞定
- 版本记录: 新增v0.7.3条目
- AI对话链路实施计划: Phase 1-6 全部标记已实施
- 新增架构图/时序图/类图(mermaid)

## 部署路径修正
- 服务器项目根路径: /opt/wecom-it-desk/
- 所有前端dist均为ro bind mount,只能在宿主机源路径操作
- 服务器nginx /h5/ 是静态文件服务(非proxy_pass)
- elFinder上传二进制不可靠(MD5不匹配),改用base64分块上传
2026-07-13 02:17:03 +08:00

233 lines
9.4 KiB
Python
Raw Permalink 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.
# =============================================================================
# 企微IT智能服务台 — 诊断相关模型
# =============================================================================
# 说明:包含3张表,支撑三层诊断闭环:
# 1. diagnostic_templates: 原子化诊断检查项模板库(管理员预置)
# 2. diagnostic_reports: 客户端/API采集的诊断报告存储
# 3. diagnostic_dispatches: 诊断下发记录,追踪 dispatch→execute→analyze→resolve 闭环
#
# 三层诊断架构:
# Layer 1 — 火绒/联软API静默采集(check_type=api, api_source=huorong/lianruan
# Layer 2 — 客户端脚本兜底(check_type=script, script_template=PowerShell/zsh
# Layer 3 — AI分析报告 + 修复包推送(fix_template + risk_level分级审批)
# =============================================================================
import uuid
from datetime import datetime
from typing import Any, Dict, List, Optional
from sqlalchemy import Boolean, DateTime, Index, Integer, JSON, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from app.database import Base
class DiagnosticTemplate(Base):
"""诊断模板 — 原子化检查项。
每条记录是一个独立的检查单元(如"ping网关""查DNS配置"),
管理员在后台预置,AI只负责选择哪些检查项组合,不生成脚本内容。
Attributes:
id: 模板唯一标识(UUID)
category: 问题类别(network/vpn/email/system/printer/security/office
name: 检查项名称(如"网关连通性检测"
check_type: 检查类型(api=服务端API采集 / script=客户端脚本采集)
api_source: API来源(huorong/lianruan),仅check_type=api时有效
api_method: 调用的API方法名(如get_terminal_detail),仅check_type=api时有效
script_template: PowerShell/zsh脚本模板(参数化),仅check_type=script时有效
fix_template: 对应的修复脚本模板(可选,部分检查项有配套修复)
fix_risk_level: 修复风险等级(low/medium/high),决定审批流程
target_condition: 触发此检查项的条件(如"dns_resolution=fail"
description: 检查项描述
is_active: 是否启用
"""
__tablename__ = "diagnostic_templates"
id: Mapped[str] = mapped_column(
String(36), primary_key=True, default=lambda: str(uuid.uuid4())
)
category: Mapped[str] = mapped_column(
String(50), nullable=False, comment="问题类别"
)
name: Mapped[str] = mapped_column(
String(200), nullable=False, comment="检查项名称"
)
check_type: Mapped[str] = mapped_column(
String(20), nullable=False, default="api",
comment="检查类型: api/script"
)
api_source: Mapped[Optional[str]] = mapped_column(
String(50), nullable=True, comment="API来源: huorong/lianruan"
)
api_method: Mapped[Optional[str]] = mapped_column(
String(100), nullable=True, comment="调用的API方法名"
)
script_template: Mapped[Optional[str]] = mapped_column(
Text, nullable=True, comment="脚本模板(PowerShell/zsh)"
)
fix_template: Mapped[Optional[str]] = mapped_column(
Text, nullable=True, comment="修复脚本模板"
)
fix_risk_level: Mapped[str] = mapped_column(
String(20), nullable=False, default="medium",
comment="修复风险等级: low/medium/high"
)
target_condition: Mapped[Optional[str]] = mapped_column(
String(200), nullable=True, comment="触发条件"
)
description: Mapped[Optional[str]] = mapped_column(
Text, nullable=True, comment="检查项描述"
)
is_active: Mapped[bool] = mapped_column(
Boolean, nullable=False, default=True, comment="是否启用"
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, default=datetime.now,
comment="创建时间"
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, default=datetime.now,
onupdate=datetime.now, comment="更新时间"
)
__table_args__ = (
Index("idx_diag_tpl_category", "category"),
Index("idx_diag_tpl_type", "check_type"),
Index("idx_diag_tpl_active", "is_active"),
)
def __repr__(self) -> str:
return f"<DiagnosticTemplate(id={self.id}, name={self.name}, type={self.check_type})>"
class DiagnosticDispatch(Base):
"""诊断下发记录 — 追踪每次诊断的完整生命周期。
状态流转:dispatched → executed → analyzed → resolved
Attributes:
id: 下发记录ID
conversation_id: 关联的会话ID
employee_id: 员工ID
template_ids: 下发的诊断模板ID列表(JSON数组)
script_content: 实际生成的脚本内容(参数化后的最终版本)
script_hash: 脚本SHA256哈希(审计追溯)
upload_token: 一次性上传token(绑定session+employee+TTL
status: 状态(dispatched/executed/analyzed/resolved
report_id: 关联的诊断报告ID(报告上传后填入)
fix_dispatched: 是否已下发修复包
created_at: 下发时间
completed_at: 完成(resolved)时间
"""
__tablename__ = "diagnostic_dispatches"
id: Mapped[str] = mapped_column(
String(36), primary_key=True, default=lambda: str(uuid.uuid4())
)
conversation_id: Mapped[str] = mapped_column(
String(36), nullable=False, comment="关联会话ID"
)
employee_id: Mapped[str] = mapped_column(
String(64), nullable=False, comment="员工ID"
)
template_ids: Mapped[list] = mapped_column(
JSON, nullable=False, default=list, comment="诊断模板ID列表"
)
script_content: Mapped[Optional[str]] = mapped_column(
Text, nullable=True, comment="生成的脚本内容"
)
script_hash: Mapped[Optional[str]] = mapped_column(
String(64), nullable=True, comment="脚本SHA256哈希"
)
upload_token: Mapped[Optional[str]] = mapped_column(
String(128), nullable=True, comment="一次性上传token"
)
status: Mapped[str] = mapped_column(
String(20), nullable=False, default="dispatched",
comment="状态: dispatched/executed/analyzed/resolved"
)
report_id: Mapped[Optional[str]] = mapped_column(
String(36), nullable=True, comment="关联诊断报告ID"
)
fix_dispatched: Mapped[bool] = mapped_column(
Boolean, nullable=False, default=False, comment="是否已下发修复包"
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, default=datetime.now,
comment="下发时间"
)
completed_at: Mapped[Optional[datetime]] = mapped_column(
DateTime(timezone=True), nullable=True, comment="完成时间"
)
__table_args__ = (
Index("idx_diag_dispatch_conv", "conversation_id"),
Index("idx_diag_dispatch_employee", "employee_id"),
Index("idx_diag_dispatch_status", "status"),
)
def __repr__(self) -> str:
return f"<DiagnosticDispatch(id={self.id}, conv={self.conversation_id}, status={self.status})>"
class DiagnosticReport(Base):
"""诊断报告 — 存储采集到的检查结果和AI分析结论。
Attributes:
id: 报告ID
dispatch_id: 关联的下发记录ID
conversation_id: 关联的会话ID
employee_id: 员工ID
template_ids: 涉及的诊断模板ID列表
report_data: 检查结果JSON[{name, status, detail, raw_output}]
ai_analysis: AI分析结论JSON{root_cause, confidence, suggested_actions}
status: 报告状态(pending/analyzed/resolved
created_at: 报告上传时间
"""
__tablename__ = "diagnostic_reports"
id: Mapped[str] = mapped_column(
String(36), primary_key=True, default=lambda: str(uuid.uuid4())
)
dispatch_id: Mapped[Optional[str]] = mapped_column(
String(36), nullable=True, comment="关联下发记录ID"
)
conversation_id: Mapped[str] = mapped_column(
String(36), nullable=False, comment="关联会话ID"
)
employee_id: Mapped[str] = mapped_column(
String(64), nullable=False, comment="员工ID"
)
template_ids: Mapped[list] = mapped_column(
JSON, nullable=False, default=list, comment="涉及诊断模板ID列表"
)
report_data: Mapped[Dict[str, Any]] = mapped_column(
JSON, nullable=False, default=dict,
comment="检查结果: [{name, status(pass/fail/warn/pending), detail, raw_output}]"
)
ai_analysis: Mapped[Optional[Dict[str, Any]]] = mapped_column(
JSON, nullable=True,
comment="AI分析: {root_cause, confidence, severity, suggested_actions}"
)
status: Mapped[str] = mapped_column(
String(20), nullable=False, default="pending",
comment="报告状态: pending/analyzed/resolved"
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, default=datetime.now,
comment="报告上传时间"
)
__table_args__ = (
Index("idx_diag_report_conv", "conversation_id"),
Index("idx_diag_report_employee", "employee_id"),
Index("idx_diag_report_status", "status"),
)
def __repr__(self) -> str:
return f"<DiagnosticReport(id={self.id}, conv={self.conversation_id}, status={self.status})>"