Files
makemd/server/src/services/GlobalCSMonitor.ts

52 lines
2.2 KiB
TypeScript
Raw Normal View History

import db from '../config/database';
import { logger } from '../utils/logger';
import { DecisionExplainabilityEngine } from '../core/ai/DecisionExplainabilityEngine';
/**
* [BIZ_OPS_150] (Sentiment)
* @description
*/
export class GlobalCSMonitor {
/**
* (BIZ_OPS_150)
*/
static async monitorSentimentDrift(tenantId: string, ticketId: string): Promise<any> {
logger.info(`[CSMonitor] Monitoring sentiment for Ticket: ${ticketId}, Tenant: ${tenantId}`);
try {
// 1. 模拟获取对话情感得分
// 假设检测到德语客服回复后,客户情感分从 0.6 降至 0.2
const sentimentTrend = [0.6, 0.55, 0.21];
const currentSentiment = sentimentTrend[sentimentTrend.length - 1];
// 2. 极性偏移识别
if (currentSentiment < 0.3) {
const advice = `CRITICAL SENTIMENT DRIFT: Ticket ${ticketId} shows sharp negative sentiment shift. ` +
`Potential cultural misunderstanding or translation error detected in non-English communication. ` +
`Suggesting immediate supervisor takeover.`;
// 3. [UX_XAI_01] 记录决策证据链
await DecisionExplainabilityEngine.logDecision({
tenantId,
module: 'CUSTOMER_SUCCESS_GOVERNANCE',
resourceId: ticketId,
decisionType: 'SENTIMENT_DRIFT_WARNING',
causalChain: advice,
factors: [
{ name: 'CurrentSentiment', value: currentSentiment, weight: 0.8, impact: 'NEGATIVE' },
{ name: 'SentimentDelta', value: sentimentTrend[0] - currentSentiment, weight: 0.2, impact: 'NEGATIVE' }
],
traceId: 'cs-monitor-' + Date.now()
});
return { success: true, riskLevel: 'CRITICAL', currentSentiment, advice, status: 'PENDING_REVIEW' };
}
return { success: true, riskLevel: 'LOW', currentSentiment };
} catch (err: any) {
logger.error(`[CSMonitor][WARN] Monitoring failed: ${err.message}`);
return { success: false, error: err.message };
}
}
}