- Create troubleshoot_sessions table in D1 - Replace KV session storage with D1 - Unify field names to snake_case (user_id, collected_info, created_at, updated_at, expires_at) - Add __PASSTHROUGH__/__SESSION_END__ marker support - Change handler signature to match domain/deposit pattern - Extract system prompt to constant TROUBLESHOOT_EXPERT_PROMPT - Add hasTroubleshootSession() for routing - Update openai-service.ts to use new D1-based functions - Update troubleshoot-tool.ts to use D1 instead of KV - Add TroubleshootSessionStatus type Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
69 lines
2.6 KiB
TypeScript
69 lines
2.6 KiB
TypeScript
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<string> {
|
|
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' +
|
|
'• "데이터베이스 연결이 느려요"';
|
|
}
|