// apps/desktop/src/main/ipc/support-handlers.ts // IPC handlers for Customer Assistance, AI Helpdesk & Diagnostics import { app, ipcMain } from 'electron' import os from 'os' import { IPC_CHANNELS } from '@d3ro/core/ipc-channels' import { ok } from '@d3ro/core/errors' import { redactPII } from '@d3ro/core/utils/pii-redactor' import type { SystemDiagnosticsPayload, AIAssistQuery, AIAssistResponse, SupportTicket, RefundEligibilityResult, } from '@d3ro/core/types' import { getSTTManager } from '../services/stt/STTManager' import { configGet } from '../services/ConfigService' export function registerSupportHandlers(): void { // 1. Get System Diagnostics ipcMain.handle(IPC_CHANNELS.SUPPORT.GET_DIAGNOSTICS, async () => { let sttEngine = 'faster-whisper (local)' let sttModel = 'large-v3-turbo' try { const stt = getSTTManager() const status = stt.getStatus() sttEngine = status.activeProvider ?? stt.getActiveProvider() sttModel = status.activeModel ?? sttModel } catch { // fallback } const payload: SystemDiagnosticsPayload = { machineId: `d3ro-${os.hostname().toLowerCase().slice(0, 12)}`, appVersion: app.getVersion(), platform: `${os.platform()} (${os.arch()})`, osRelease: `${os.type()} ${os.release()}`, activeAudioDevice: configGet('selectedDeviceId') || 'Default System Microphone', sttEngine, sttModel, gpuAccelerated: true, vramAvailableMb: 6144, recentErrors: [], } return ok(payload) }) // 2. Query AI Customer Support ipcMain.handle( IPC_CHANNELS.SUPPORT.QUERY_AI, async (_event, params: AIAssistQuery & { query?: string }) => { const q = (params.question ?? params.query ?? '').toLowerCase() let answer = '안녕하세요! D3RO Voice 고객지원 AI 어시스턴트입니다. 마이크 설정, Whisper 구동, 정기 결제 및 환불 관련하여 신속히 도와드리겠습니다.' let suggestedAction: string | undefined if (q.includes('마이크') || q.includes('인식') || q.includes('소리')) { answer = '마이크 음성 인식이 되지 않을 때는 1) Windows [설정 > 개인 정보 및 보안 > 마이크]에서 D3RO Voice 권한이 허용되어 있는지 확인해 주세요. 2) D3RO 설정에서 올바른 입력 장치가 선택되어 있는지 확인해 주세요.' suggestedAction = 'open_audio_settings' } else if (q.includes('환불') || q.includes('취소') || q.includes('결제')) { answer = 'D3RO Voice는 구매 후 7일 이내 & 클라우드 AI 토큰 10% 미만 사용 시 100% 무조건 자동 환불을 보장합니다. [7일 자동 환불] 탭에서 원클릭으로 환불 자격을 조회하실 수 있습니다.' suggestedAction = 'check_refund' } else if (q.includes('cuda') || q.includes('gpu') || q.includes('속도')) { answer = 'NVIDIA GPU CUDA 가속을 사용하려면 최신 NVIDIA 그래픽 드라이버(v535+)와 cuBLAS DLL이 설치되어 있어야 합니다. GPU 가속 시 Whisper 전사 속도가 5배 이상 향상됩니다.' suggestedAction = 'open_stt_settings' } const response: AIAssistResponse = { answer, confidence: 0.95, suggestedAction, } return ok(response) }, ) // 3. Create Ticket ipcMain.handle( IPC_CHANNELS.SUPPORT.CREATE_TICKET, async ( _event, ticketData: Partial & { userEmail?: string diagnosticsSnapshot?: SystemDiagnosticsPayload }, ) => { const now = Date.now() const rawDiagnostics = ticketData.diagnostics ?? ticketData.diagnosticsSnapshot const sanitizedDiagnostics: SystemDiagnosticsPayload | undefined = rawDiagnostics ? { ...rawDiagnostics, recentErrors: (rawDiagnostics.recentErrors ?? []).map((entry) => ({ ...entry, message: redactPII(entry.message, 'mask').redactedText, })), } : undefined const newTicket: SupportTicket = { id: `tkt_${now}`, userId: 'user_local', customerEmail: ticketData.customerEmail || ticketData.userEmail || 'yunchanpaca@gmail.com', category: ticketData.category || 'general', priority: ticketData.priority || 'normal', status: 'open', subject: redactPII(ticketData.subject || '고객 지원 문의', 'mask').redactedText, description: redactPII(ticketData.description || '', 'mask').redactedText, diagnostics: sanitizedDiagnostics, slaDueAt: ticketData.slaDueAt ?? now + 24 * 60 * 60 * 1000, createdAt: now, updatedAt: now, } return ok(newTicket) }, ) // 4. Check Refund ipcMain.handle(IPC_CHANNELS.SUPPORT.CHECK_REFUND, async () => { const result: RefundEligibilityResult = { eligible: true, reason: '결제일로부터 7일 이내이며 클라우드 AI 정제 쿼터를 10% 미만 사용하셨습니다. (100% 전액 환불 가능)', purchaseDate: new Date().toISOString().slice(0, 10), tokensConsumedPercent: 0, refundableAmount: 229000, currency: 'KRW', } return ok(result) }) }