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分块上传
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
%% 坐席端 AI 辅助消息框 — 类图
|
||||
%% 文档版本: v1.0
|
||||
%% 创建日期: 2026-07-11
|
||||
|
||||
classDiagram
|
||||
direction TB
|
||||
|
||||
class WingmanService {
|
||||
-str api_url
|
||||
-str api_key
|
||||
-float timeout
|
||||
-httpx.AsyncClient _client
|
||||
-aioredis.Redis _redis
|
||||
-str _COMPLETION_SYSTEM_PROMPT
|
||||
-str _TONE_ADJUST_SYSTEM_PROMPT
|
||||
-str _POLISH_SYSTEM_PROMPT
|
||||
-str _REWRITE_SYSTEM_PROMPT
|
||||
+__init__(redis_client: Optional[Redis])
|
||||
+async generate_completion(conversation_id: str, current_text: str, messages: List[Dict], max_length: int) Dict
|
||||
+async adjust_tone(conversation_id: str, selected_text: str, full_text: str, tone: str, messages: List[Dict]) Dict
|
||||
+async polish_text(conversation_id: str, text: str, action: str, messages: List[Dict]) Dict
|
||||
+async rewrite_versions(conversation_id: str, current_text: str, messages: List[Dict], generate_count: int, include_knowledge: bool) Dict
|
||||
-async _call_wingman_api(context_messages: List[Dict], temperature: float) Optional[str]
|
||||
-_build_context_messages(messages: List[Dict], system_prompt: str) List[Dict]
|
||||
-async _get_cache(key: str) Optional[Dict]
|
||||
-async _set_cache(key: str, value: Dict, ttl: int) void
|
||||
-_make_cache_key(text: str, conversation_id: str) str
|
||||
-async _search_knowledge(query: str) Optional[str]
|
||||
-_parse_json_response(content: str, default: Dict) Dict
|
||||
}
|
||||
|
||||
class WingmanAPIRouter {
|
||||
+POST autocomplete(conversation_id, request: AutocompleteRequest, agent, db, wingman_service)
|
||||
+POST tone_adjust(conversation_id, request: ToneAdjustRequest, agent, db, wingman_service)
|
||||
+POST polish(conversation_id, request: PolishRequest, agent, db, wingman_service)
|
||||
+POST rewrite(conversation_id, request: RewriteRequest, agent, db, wingman_service)
|
||||
-async _validate_conversation(conversation_id, agent, db) Conversation
|
||||
-async _get_recent_messages(conversation_id, db, limit) List[Dict]
|
||||
}
|
||||
|
||||
class AutocompleteRequest {
|
||||
+str current_text
|
||||
+int cursor_position
|
||||
+int max_length
|
||||
}
|
||||
|
||||
class ToneAdjustRequest {
|
||||
+str selected_text
|
||||
+str full_text
|
||||
+str tone
|
||||
}
|
||||
|
||||
class PolishRequest {
|
||||
+str text
|
||||
+str action
|
||||
+bool conversation_context
|
||||
}
|
||||
|
||||
class RewriteRequest {
|
||||
+str current_text
|
||||
+int generate_count
|
||||
+bool include_knowledge
|
||||
}
|
||||
|
||||
class WingmanTS {
|
||||
+autocomplete(convId: str, text: str, cursorPos: int, signal: AbortSignal) Promise~AutocompleteResult~
|
||||
+adjustTone(convId: str, selectedText: str, fullText: str, tone: ToneType, signal: AbortSignal) Promise~ToneAdjustResult~
|
||||
+polishText(convId: str, text: str, action: PolishAction, signal: AbortSignal) Promise~PolishResult~
|
||||
+rewriteVersions(convId: str, currentText: str, signal: AbortSignal) Promise~RewriteResult~
|
||||
}
|
||||
|
||||
class UseAiAssist {
|
||||
+Ref~string~ ghostText
|
||||
+Ref~boolean~ isCompletLoading
|
||||
+Ref~boolean~ autocompleteEnabled
|
||||
+Ref~boolean~ tonePopoverVisible
|
||||
+Ref~boolean~ polishPanelVisible
|
||||
+Ref~boolean~ rewritePanelVisible
|
||||
+triggerAutocomplete() void
|
||||
+acceptGhostText() void
|
||||
+clearGhostText() void
|
||||
+adjustTone(selectedText: str, fullText: str, tone: ToneType) Promise~void~
|
||||
+polishText(action: PolishAction) Promise~void~
|
||||
+rewriteVersions() Promise~void~
|
||||
+cleanup() void
|
||||
}
|
||||
|
||||
class GhostText {
|
||||
+Props: ghostText: string, textareaRef: HTMLTextAreaElement
|
||||
+Emits: accept, dismiss
|
||||
-calculateCursorPos(textarea: HTMLTextAreaElement) {x: number, y: number}
|
||||
}
|
||||
|
||||
class AiAssistToolbar {
|
||||
+Props: autocompleteEnabled: boolean, hasSelection: boolean, hasText: boolean
|
||||
+Emits: toggleAutocomplete, toneAdjust, polish, rewrite
|
||||
}
|
||||
|
||||
class ToneAdjustPopover {
|
||||
+Props: visible: boolean, loading: boolean, result: ToneAdjustResult|null, originalText: string
|
||||
+Emits: select(tone: ToneType), replace, cancel
|
||||
}
|
||||
|
||||
class PolishPanel {
|
||||
+Props: visible: boolean, loading: boolean, result: PolishResult|null, originalText: string
|
||||
+Emits: action(action: PolishAction), replace(text: string), cancel
|
||||
}
|
||||
|
||||
class RewritePanel {
|
||||
+Props: visible: boolean, loading: boolean, result: RewriteResult|null
|
||||
+Emits: replace(text: string), append(text: string), cancel
|
||||
}
|
||||
|
||||
class ReplyBox {
|
||||
-UseAiAssist aiAssist
|
||||
-Ref~string~ inputText
|
||||
-HTMLTextAreaElement inputRef
|
||||
+handleKeydown(event: KeyboardEvent) void
|
||||
+handleInput() void
|
||||
}
|
||||
|
||||
%% 后端关系
|
||||
WingmanAPIRouter --> WingmanService : Depends (DI)
|
||||
WingmanAPIRouter --> AutocompleteRequest : 验证请求体
|
||||
WingmanAPIRouter --> ToneAdjustRequest : 验证请求体
|
||||
WingmanAPIRouter --> PolishRequest : 验证请求体
|
||||
WingmanAPIRouter --> RewriteRequest : 验证请求体
|
||||
|
||||
%% 前端关系
|
||||
WingmanTS --> AutocompleteRequest : HTTP 请求
|
||||
UseAiAssist --> WingmanTS : 调用 API
|
||||
ReplyBox --> UseAiAssist : composable
|
||||
ReplyBox --> GhostText : 渲染幽灵文字
|
||||
ReplyBox --> AiAssistToolbar : 渲染工具栏
|
||||
ReplyBox --> ToneAdjustPopover : 弹出浮层
|
||||
ReplyBox --> PolishPanel : 弹出面板
|
||||
ReplyBox --> RewritePanel : 弹出面板
|
||||
@@ -0,0 +1,261 @@
|
||||
%% 坐席端 AI 辅助消息框 — 时序图
|
||||
%% 文档版本: v1.0
|
||||
%% 创建日期: 2026-07-11
|
||||
%% 包含 4 个功能的完整调用流程
|
||||
|
||||
%% ==========================================================================
|
||||
%% 4.1 实时自动补齐
|
||||
%% ==========================================================================
|
||||
sequenceDiagram
|
||||
participant User as 坐席
|
||||
participant RB as ReplyBox.vue
|
||||
participant GT as GhostText.vue
|
||||
participant Cmp as useAiAssist.ts
|
||||
participant API as wingman.ts
|
||||
participant BE as wingman.py<br/>(autocomplete)
|
||||
participant Svc as WingmanService<br/>.generate_completion()
|
||||
participant Redis as Redis
|
||||
participant Dify as Dify AI
|
||||
|
||||
User->>RB: 输入文字
|
||||
RB->>Cmp: handleInput() → triggerAutocomplete()
|
||||
|
||||
Note over Cmp: debounce 800ms 等待
|
||||
Note over Cmp: 输入停顿 > 800ms 触发
|
||||
|
||||
Cmp->>Cmp: abort 上一个 AbortController
|
||||
Cmp->>Cmp: 创建新 AbortController
|
||||
|
||||
Note over Cmp: 检查:输入 > 5 字符 && autocompleteEnabled
|
||||
|
||||
Cmp->>API: autocomplete(convId, text, cursorPos, signal)
|
||||
API->>BE: POST /conversations/{id}/wingman/autocomplete
|
||||
|
||||
BE->>BE: _validate_conversation()
|
||||
BE->>BE: _get_recent_messages(limit=5)
|
||||
BE->>Svc: generate_completion(conv_id, text, messages)
|
||||
|
||||
Svc->>Svc: _make_cache_key(text, conv_id)
|
||||
Svc->>Redis: GET wingman:autocomplete:{hash}
|
||||
|
||||
alt Redis 命中缓存
|
||||
Redis-->>Svc: {completion, confidence}
|
||||
Svc-->>BE: 缓存结果
|
||||
else Redis 未命中
|
||||
Redis-->>Svc: nil
|
||||
Svc->>Svc: _build_context_messages(messages, _COMPLETION_SYSTEM_PROMPT)
|
||||
Svc->>Svc: 追加 user 消息: "坐席正在输入:{text}\n请补齐"
|
||||
Svc->>Dify: POST /chat/completions<br/>{temperature: 0.2}
|
||||
Dify-->>Svc: "正在查看相关工单记录..."
|
||||
Svc->>Redis: SETEX wingman:autocomplete:{hash} 30s
|
||||
Svc-->>BE: {completion, confidence}
|
||||
end
|
||||
|
||||
BE-->>API: {code: 0, data: {completion, confidence}}
|
||||
API-->>Cmp: AutocompleteResult
|
||||
|
||||
Note over Cmp: 检查:未被 abort && completion 非空
|
||||
|
||||
Cmp->>Cmp: ghostText.value = completion
|
||||
Cmp->>GT: 渲染幽灵文字(灰色斜体)
|
||||
GT-->>User: 光标位置显示灰色补齐文字
|
||||
|
||||
alt Tab 键接受
|
||||
User->>RB: 按 Tab
|
||||
RB->>Cmp: acceptGhostText()
|
||||
Cmp->>RB: inputText += ghostText
|
||||
Cmp->>Cmp: ghostText = ''
|
||||
GT-->>User: 幽灵文字消失,文字变为正常颜色
|
||||
else 继续输入
|
||||
User->>RB: 继续输入
|
||||
RB->>Cmp: clearGhostText()
|
||||
Cmp->>Cmp: ghostText = ''
|
||||
Note over Cmp: 重新触发 debounce
|
||||
else Esc 键
|
||||
User->>RB: 按 Esc
|
||||
RB->>Cmp: clearGhostText()
|
||||
Cmp->>Cmp: ghostText = ''
|
||||
end
|
||||
|
||||
%% ==========================================================================
|
||||
%% 4.2 语气调整
|
||||
%% ==========================================================================
|
||||
sequenceDiagram
|
||||
participant User as 坐席
|
||||
participant RB as ReplyBox.vue
|
||||
participant TAP as ToneAdjustPopover.vue
|
||||
participant Cmp as useAiAssist.ts
|
||||
participant API as wingman.ts
|
||||
participant BE as wingman.py<br/>(tone-adjust)
|
||||
participant Svc as WingmanService<br/>.adjust_tone()
|
||||
participant Dify as Dify AI
|
||||
|
||||
User->>RB: 选中输入框文字(≥ 5 字符)
|
||||
User->>RB: 点击工具栏"语气"按钮
|
||||
|
||||
RB->>TAP: visible = true(弹出浮层)
|
||||
TAP-->>User: 显示 3 种语气选项
|
||||
|
||||
User->>TAP: 点击"专业"
|
||||
TAP->>Cmp: adjustTone(selectedText, fullText, 'professional')
|
||||
|
||||
Cmp->>Cmp: toneLoading = true
|
||||
Cmp->>API: adjustTone(convId, selectedText, fullText, 'professional', signal)
|
||||
API->>BE: POST /conversations/{id}/wingman/tone-adjust
|
||||
BE->>BE: _validate_conversation()
|
||||
BE->>BE: _get_recent_messages(limit=5)
|
||||
BE->>Svc: adjust_tone(conv_id, selectedText, fullText, 'professional', messages)
|
||||
|
||||
Svc->>Svc: _build_context_messages(messages, _TONE_ADJUST_SYSTEM_PROMPT)
|
||||
Svc->>Svc: 追加 user 消息: "原文:{selectedText}\n完整内容:{fullText}\n改写为{tone}风格"
|
||||
Svc->>Dify: POST /chat/completions<br/>{temperature: 0.3}
|
||||
Dify-->>Svc: "经排查,您的VPN连接异常..."
|
||||
|
||||
Svc-->>BE: {rewritten_text, tone, changes_summary}
|
||||
BE-->>API: {code: 0, data: {...}}
|
||||
API-->>Cmp: ToneAdjustResult
|
||||
|
||||
Cmp->>Cmp: toneResult = result
|
||||
Cmp->>Cmp: toneLoading = false
|
||||
Cmp->>TAP: 显示原文/改写文对比
|
||||
|
||||
TAP-->>User: 原文 → 改写文 + 变更说明
|
||||
|
||||
alt 点击"替换"
|
||||
User->>TAP: 点击"替换"
|
||||
TAP->>RB: emit('replace', rewritten_text)
|
||||
RB->>RB: 用 rewritten_text 替换选中区域
|
||||
RB->>TAP: visible = false
|
||||
else 点击"取消"或外部
|
||||
User->>TAP: 点击取消
|
||||
TAP->>RB: emit('cancel')
|
||||
RB->>TAP: visible = false
|
||||
end
|
||||
|
||||
%% ==========================================================================
|
||||
%% 4.3 文字润色
|
||||
%% ==========================================================================
|
||||
sequenceDiagram
|
||||
participant User as 坐席
|
||||
participant RB as ReplyBox.vue
|
||||
participant PP as PolishPanel.vue
|
||||
participant Cmp as useAiAssist.ts
|
||||
participant API as wingman.ts
|
||||
participant BE as wingman.py<br/>(polish)
|
||||
participant Svc as WingmanService<br/>.polish_text()
|
||||
participant Dify as Dify AI
|
||||
|
||||
User->>RB: 点击工具栏"润色"按钮
|
||||
RB->>PP: visible = true(弹出精修面板)
|
||||
PP-->>User: 显示原文 + 3 个操作按钮
|
||||
|
||||
User->>PP: 点击"扩写"
|
||||
PP->>Cmp: polishText('expand')
|
||||
|
||||
Cmp->>Cmp: polishLoading = true
|
||||
Cmp->>API: polishText(convId, inputText, 'expand', signal)
|
||||
API->>BE: POST /conversations/{id}/wingman/polish
|
||||
BE->>BE: _validate_conversation()
|
||||
BE->>BE: _get_recent_messages(limit=5)
|
||||
BE->>Svc: polish_text(conv_id, text, 'expand', messages)
|
||||
|
||||
Svc->>Svc: _build_context_messages(messages, _POLISH_SYSTEM_PROMPT)
|
||||
Svc->>Svc: 追加 user 消息: "对以下文字进行扩写:{text}"
|
||||
Svc->>Dify: POST /chat/completions<br/>{temperature: 0.3}
|
||||
Dify-->>Svc: "建议您按以下步骤操作:\n1. 退出VPN..."
|
||||
|
||||
Svc-->>BE: {polished_text, action, changes_summary}
|
||||
BE-->>API: {code: 0, data: {...}}
|
||||
API-->>Cmp: PolishResult
|
||||
|
||||
Cmp->>Cmp: polishResult = result
|
||||
Cmp->>Cmp: polishLoading = false
|
||||
Cmp->>PP: 显示左右对比(原文 | 结果)
|
||||
|
||||
PP-->>User: 左侧原文 | 右侧结果(可编辑)+ 变更说明
|
||||
|
||||
Note over User,PP: 坐席可在结果区域手动编辑
|
||||
|
||||
alt 点击"替换全部"
|
||||
User->>PP: 编辑后点击"替换全部"
|
||||
PP->>RB: emit('replace', editedText)
|
||||
RB->>RB: inputText = editedText
|
||||
RB->>PP: visible = false
|
||||
else 切换操作
|
||||
User->>PP: 点击"压缩"或"纠错"
|
||||
PP->>Cmp: polishText('compress' | 'correct')
|
||||
Note over Cmp,Dify: 重新调用流程
|
||||
else 点击"取消"
|
||||
User->>PP: 点击取消
|
||||
PP->>RB: emit('cancel')
|
||||
RB->>PP: visible = false
|
||||
end
|
||||
|
||||
%% ==========================================================================
|
||||
%% 4.4 智能改写
|
||||
%% ==========================================================================
|
||||
sequenceDiagram
|
||||
participant User as 坐席
|
||||
participant RB as ReplyBox.vue
|
||||
participant RP as RewritePanel.vue
|
||||
participant Cmp as useAiAssist.ts
|
||||
participant API as wingman.ts
|
||||
participant BE as wingman.py<br/>(rewrite)
|
||||
participant Svc as WingmanService<br/>.rewrite_versions()
|
||||
participant RAG as RAGFlow
|
||||
participant Dify as Dify AI
|
||||
|
||||
User->>RB: 点击工具栏"改写"按钮
|
||||
RB->>RP: visible = true(弹出选择面板)
|
||||
|
||||
RP->>Cmp: rewriteVersions()
|
||||
Cmp->>Cmp: rewriteLoading = true
|
||||
Cmp->>API: rewriteVersions(convId, inputText, signal)
|
||||
API->>BE: POST /conversations/{id}/wingman/rewrite
|
||||
BE->>BE: _validate_conversation()
|
||||
BE->>BE: _get_recent_messages(limit=10)
|
||||
BE->>Svc: rewrite_versions(conv_id, text, messages, generate_count=3, include_knowledge=true)
|
||||
|
||||
Note over Svc: 构建上下文
|
||||
|
||||
Svc->>Svc: _build_context_messages(messages, _REWRITE_SYSTEM_PROMPT)
|
||||
|
||||
par 知识库检索(并行)
|
||||
Svc->>RAG: retrieval(question=当前问题, dataset_ids=默认知识库)
|
||||
RAG-->>Svc: 检索到 3 个相关文档片段
|
||||
Svc->>Svc: 将知识片段拼入 system prompt
|
||||
and 准备 Dify 调用
|
||||
Note over Svc: 等待知识检索完成
|
||||
end
|
||||
|
||||
Svc->>Dify: POST /chat/completions<br/>{temperature: 0.6}
|
||||
Dify-->>Svc: "版本1\n---\n版本2\n---\n版本3"
|
||||
|
||||
Svc->>Svc: 按 "---" 分割为 3 个版本
|
||||
Svc->>Svc: 标注 style 和 source
|
||||
|
||||
Svc-->>BE: {versions: [{text, style, source}, ...]}
|
||||
BE-->>API: {code: 0, data: {...}}
|
||||
API-->>Cmp: RewriteResult
|
||||
|
||||
Cmp->>Cmp: rewriteResult = result
|
||||
Cmp->>Cmp: rewriteLoading = false
|
||||
Cmp->>RP: 显示 3 个版本卡片
|
||||
|
||||
RP-->>User: 版本1(简洁直接)/ 版本2(详细带步骤)/ 版本3(带知识库引用)
|
||||
|
||||
alt 选择版本 → 替换
|
||||
User->>RP: 点击版本卡片 → "替换"
|
||||
RP->>RB: emit('replace', versionText)
|
||||
RB->>RB: inputText = versionText
|
||||
RB->>RP: visible = false
|
||||
else 选择版本 → 追加
|
||||
User->>RP: 点击版本卡片 → "追加"
|
||||
RP->>RB: emit('append', versionText)
|
||||
RB->>RB: inputText += '\n' + versionText
|
||||
RB->>RP: visible = false
|
||||
else 点击"取消"
|
||||
User->>RP: 点击取消
|
||||
RP->>RB: emit('cancel')
|
||||
RB->>RP: visible = false
|
||||
end
|
||||
Reference in New Issue
Block a user