import type { Env } from '../types'; import { createLogger } from '../utils/logger'; const logger = createLogger('troubleshoot-tool'); export const manageTroubleshootTool = { type: 'function', function: { name: 'manage_troubleshoot', description: '기술 문제 해결 도우미. 서버 에러, 도메인 문제, 배포 실패, 네트워크 오류, 데이터베이스 이슈 등을 진단하고 해결합니다. 사용자가 "에러", "문제", "안돼", "느려", "오류" 등을 언급하면 이 도구를 사용하세요.', parameters: { type: 'object', properties: { action: { type: 'string', enum: ['start', 'cancel'], description: 'start=문제 해결 시작, cancel=세션 취소', }, }, required: ['action'], }, }, }; export async function executeManageTroubleshoot( args: { action: 'start' | 'cancel' }, env?: Env, telegramUserId?: string ): Promise { const { action } = args; logger.info('트러블슈팅 도구 호출', { action, userId: telegramUserId }); if (!env?.DB || !telegramUserId) { return '🚫 트러블슈팅 기능을 사용할 수 없습니다.'; } const { getTroubleshootSession, createTroubleshootSession, saveTroubleshootSession, deleteTroubleshootSession } = await import('../agents/troubleshoot-agent'); if (action === 'cancel') { await deleteTroubleshootSession(env.DB, telegramUserId); return '✅ 트러블슈팅 세션이 취소되었습니다.'; } // action === 'start' const existingSession = await getTroubleshootSession(env.DB, telegramUserId); if (existingSession && existingSession.status !== 'completed') { return '이미 진행 중인 트러블슈팅 세션이 있습니다. 계속 진행해주세요.\n\n현재까지 파악된 정보:\n' + (existingSession.collected_info.category ? `• 분류: ${existingSession.collected_info.category}\n` : '') + (existingSession.collected_info.symptoms ? `• 증상: ${existingSession.collected_info.symptoms}\n` : ''); } // Create new session const newSession = createTroubleshootSession(telegramUserId, 'gathering'); await saveTroubleshootSession(env.DB, newSession); logger.info('트러블슈팅 세션 시작', { userId: telegramUserId }); return '__DIRECT__🔧 기술 문제 해결 도우미입니다.\n\n' + '어떤 문제가 발생했나요? 최대한 자세히 설명해주세요.\n\n' + '💡 예시:\n' + '• "서버가 502 에러를 반환해요"\n' + '• "도메인이 연결이 안돼요"\n' + '• "배포가 실패해요"\n' + '• "데이터베이스 연결이 느려요"'; }