272 lines
8.8 KiB
Plaintext
272 lines
8.8 KiB
Plaintext
|
|
# 复杂场景重构第一阶段 — 类图
|
||
|
|
|
||
|
|
> **关联文档**: `复杂场景重构第一阶段-架构设计.md` §3
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
```mermaid
|
||
|
|
classDiagram
|
||
|
|
direction TB
|
||
|
|
|
||
|
|
%% ==================== 数据模型层 ====================
|
||
|
|
namespace Models {
|
||
|
|
class AutoSession {
|
||
|
|
+String id
|
||
|
|
+String conversation_id
|
||
|
|
+String employee_id
|
||
|
|
+String agent_id
|
||
|
|
+String scenario_key
|
||
|
|
+String status
|
||
|
|
+String mode
|
||
|
|
+Float confidence
|
||
|
|
+JSON intent
|
||
|
|
+String current_action_id
|
||
|
|
+String title
|
||
|
|
+DateTime auto_close_at
|
||
|
|
+DateTime paused_at
|
||
|
|
+DateTime resolved_at
|
||
|
|
+String closed_by
|
||
|
|
+JSON meta
|
||
|
|
+DateTime created_at
|
||
|
|
+DateTime updated_at
|
||
|
|
}
|
||
|
|
|
||
|
|
class AutoAction {
|
||
|
|
+String id
|
||
|
|
+String session_id
|
||
|
|
+Integer action_index
|
||
|
|
+String action_type
|
||
|
|
+String adapter
|
||
|
|
+String risk_level
|
||
|
|
+String title
|
||
|
|
+String description
|
||
|
|
+String status
|
||
|
|
+JSON payload
|
||
|
|
+JSON result
|
||
|
|
+String error
|
||
|
|
+String approved_by
|
||
|
|
+DateTime approved_at
|
||
|
|
}
|
||
|
|
|
||
|
|
class InformationItem {
|
||
|
|
+String id
|
||
|
|
+String session_id
|
||
|
|
+String name
|
||
|
|
+String value
|
||
|
|
+JSON modifiers
|
||
|
|
+Boolean is_filled
|
||
|
|
+Boolean is_locked
|
||
|
|
+Integer version
|
||
|
|
+JSON update_history
|
||
|
|
+DateTime created_at
|
||
|
|
+DateTime updated_at
|
||
|
|
}
|
||
|
|
|
||
|
|
class ApprovalTicket {
|
||
|
|
+String id
|
||
|
|
+String action_id
|
||
|
|
+String session_id
|
||
|
|
+String approver_id
|
||
|
|
+String channel
|
||
|
|
+String status
|
||
|
|
+String reason
|
||
|
|
+String decision_note
|
||
|
|
+DateTime decided_at
|
||
|
|
}
|
||
|
|
|
||
|
|
class ScenarioConfig {
|
||
|
|
+String id
|
||
|
|
+String scenario_key
|
||
|
|
+String name
|
||
|
|
+String description
|
||
|
|
+Boolean enabled
|
||
|
|
+JSON trigger_conditions
|
||
|
|
+JSON actions
|
||
|
|
+JSON approval_strategy
|
||
|
|
+String current_version_id
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
%% ==================== 服务层 ====================
|
||
|
|
namespace Services {
|
||
|
|
class IntentRouter {
|
||
|
|
-db: AsyncSession
|
||
|
|
-audit: Any
|
||
|
|
+detect(description: str, employee_id: str) Dict
|
||
|
|
+detect_global_intent(text: str) Dict
|
||
|
|
-_keyword_fallback_global(text: str) Dict
|
||
|
|
}
|
||
|
|
|
||
|
|
class DifyClient {
|
||
|
|
-base_url: str
|
||
|
|
-api_key: str
|
||
|
|
-timeout: float
|
||
|
|
+detect_intent(description: str, employee_id: str) Dict
|
||
|
|
-_parse_intent(answer: str) Dict
|
||
|
|
-_parse_global_intent(answer: str) Dict
|
||
|
|
-_fallback_intent(description: str) Dict
|
||
|
|
-_fallback_global_intent(text: str) Dict
|
||
|
|
+test_connection() Dict
|
||
|
|
}
|
||
|
|
|
||
|
|
class AutoSessionService {
|
||
|
|
-db: AsyncSession
|
||
|
|
-redis: Any
|
||
|
|
-audit: Any
|
||
|
|
+create_session(...) AutoSession
|
||
|
|
+get_session(session_id) AutoSession
|
||
|
|
+list_sessions(...) List
|
||
|
|
+start(session_id) void
|
||
|
|
+pause_session(session_id, reason) AutoSession
|
||
|
|
+resume_session(employee_id, session_id) dict
|
||
|
|
+list_paused_sessions(employee_id) List
|
||
|
|
+correct_info(session_id, field, new_value) InformationItem
|
||
|
|
+supplement_info(session_id, field, value) InformationItem
|
||
|
|
+agent_resume(session_id, agent_id) AutoSession
|
||
|
|
+agent_close(session_id, agent_id) AutoSession
|
||
|
|
+takeover(session_id, agent_id) AutoSession
|
||
|
|
+resolve_feedback(session_id, satisfied) AutoSession
|
||
|
|
-_build_resume_point(session) dict
|
||
|
|
-_save_resume_point(session, snapshot) void
|
||
|
|
-_load_resume_point(session_id) dict
|
||
|
|
}
|
||
|
|
|
||
|
|
class InformationItemService {
|
||
|
|
-db: AsyncSession
|
||
|
|
-redis: Any
|
||
|
|
+create_item(session_id, name, value, modifiers) InformationItem
|
||
|
|
+get_items(session_id) List~InformationItem~
|
||
|
|
+get_item(session_id, name) InformationItem
|
||
|
|
+correct_value(session_id, name, new_value) InformationItem
|
||
|
|
+supplement_value(session_id, name, value) InformationItem
|
||
|
|
+lock_items_for_action(session_id, action_id) void
|
||
|
|
+check_downstream_impact(session_id, field) bool
|
||
|
|
+get_pending_required_items(session_id) List~str~
|
||
|
|
}
|
||
|
|
|
||
|
|
class ActionExecutor {
|
||
|
|
-db: AsyncSession
|
||
|
|
-redis: Any
|
||
|
|
-audit: Any
|
||
|
|
-approval: ApprovalService
|
||
|
|
-rollback: RollbackService
|
||
|
|
+run(session_id) void
|
||
|
|
+resume(session_id, action_id, decision) void
|
||
|
|
-_do_execute(session, action, mapping, clients) void
|
||
|
|
-_on_action_failed(session, action, exc) void
|
||
|
|
-_finish_success(session) void
|
||
|
|
}
|
||
|
|
|
||
|
|
class TimeoutCleaner {
|
||
|
|
-db_factory: async_sessionmaker
|
||
|
|
-redis: Any
|
||
|
|
+run_once() int
|
||
|
|
+run_scheduled(interval: int) void
|
||
|
|
-_scan_and_close() int
|
||
|
|
-_notify_timeout(session_id) void
|
||
|
|
}
|
||
|
|
|
||
|
|
class ProgressPublisher {
|
||
|
|
+publish_progress(session_id, step, message) void
|
||
|
|
+publish_action_required(session_id, action, ticket) void
|
||
|
|
+publish_resolved(session_id, summary) void
|
||
|
|
+publish_takeover(session_id, reason) void
|
||
|
|
+publish_error(session_id, code, message) void
|
||
|
|
+publish_paused(session_id, title, paused_at, hint) void
|
||
|
|
+publish_resumed(session_id, title, resumed_at, step) void
|
||
|
|
+publish_timeout_closed(session_id, closed_at, reason) void
|
||
|
|
+publish_info_corrected(session_id, field, old, new, ver) void
|
||
|
|
+publish_info_supplemented(session_id, field, supp, new) void
|
||
|
|
-_publish(event_type, session_id, data) void
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
%% ==================== Schema 层 ====================
|
||
|
|
namespace Schemas {
|
||
|
|
class GlobalIntentResult {
|
||
|
|
+Optional~str~ global_intent
|
||
|
|
+Optional~str~ scenario_key
|
||
|
|
+float confidence
|
||
|
|
+Optional~str~ corrected_field
|
||
|
|
+Optional~str~ old_value
|
||
|
|
+Optional~str~ new_value
|
||
|
|
+Optional~str~ supplement_field
|
||
|
|
+Optional~str~ supplement_value
|
||
|
|
+str raw
|
||
|
|
+str error
|
||
|
|
}
|
||
|
|
|
||
|
|
class PauseRequest {
|
||
|
|
+Optional~str~ reason
|
||
|
|
}
|
||
|
|
|
||
|
|
class ResumeRequest {
|
||
|
|
+Optional~str~ session_id
|
||
|
|
}
|
||
|
|
|
||
|
|
class CorrectRequest {
|
||
|
|
+str field
|
||
|
|
+str new_value
|
||
|
|
+Optional~str~ old_value
|
||
|
|
}
|
||
|
|
|
||
|
|
class SupplementRequest {
|
||
|
|
+str field
|
||
|
|
+str value
|
||
|
|
}
|
||
|
|
|
||
|
|
class InformationItemResponse {
|
||
|
|
+str id
|
||
|
|
+str session_id
|
||
|
|
+str name
|
||
|
|
+str value
|
||
|
|
+List~str~ modifiers
|
||
|
|
+bool is_filled
|
||
|
|
+bool is_locked
|
||
|
|
+int version
|
||
|
|
+List~dict~ update_history
|
||
|
|
+Optional~str~ updated_at
|
||
|
|
}
|
||
|
|
|
||
|
|
class ResumePointResponse {
|
||
|
|
+str session_id
|
||
|
|
+str title
|
||
|
|
+Optional~str~ scenario_key
|
||
|
|
+str current_step
|
||
|
|
+Optional~str~ paused_at
|
||
|
|
+List~str~ pending_items
|
||
|
|
+List~InformationItemResponse~ info_items
|
||
|
|
}
|
||
|
|
|
||
|
|
class PausedSessionItem {
|
||
|
|
+str session_id
|
||
|
|
+str title
|
||
|
|
+Optional~str~ scenario_key
|
||
|
|
+Optional~str~ paused_at
|
||
|
|
+str paused_duration
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
%% ==================== 关系 ====================
|
||
|
|
AutoSession "1" --> "*" InformationItem : session_id 关联
|
||
|
|
AutoSession "1" --> "*" AutoAction : session_id 关联
|
||
|
|
AutoSession "1" --> "*" ApprovalTicket : session_id 关联
|
||
|
|
ScenarioConfig --> AutoSession : scenario_key 匹配
|
||
|
|
|
||
|
|
AutoSessionService --> AutoSession : 管理生命周期
|
||
|
|
AutoSessionService --> InformationItemService : 委托信息项操作
|
||
|
|
AutoSessionService --> IntentRouter : 使用意图识别
|
||
|
|
AutoSessionService --> ActionExecutor : 调用续行执行
|
||
|
|
AutoSessionService --> ProgressPublisher : 推送事件
|
||
|
|
|
||
|
|
IntentRouter --> DifyClient : 调用 Dify 识别
|
||
|
|
InformationItemService --> InformationItem : CRUD
|
||
|
|
TimeoutCleaner --> AutoSessionService : 调用 auto_close
|
||
|
|
TimeoutCleaner --> ProgressPublisher : 推送超时事件
|
||
|
|
ProgressPublisher --> AutoSession : 推送状态变更
|
||
|
|
|
||
|
|
InformationItemResponse ..> InformationItem : 序列化
|
||
|
|
ResumePointResponse ..> InformationItemResponse : 包含
|
||
|
|
GlobalIntentResult ..> IntentRouter : 返回类型
|
||
|
|
```
|