refactor: migrate troubleshoot-agent from KV to D1
- 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>
This commit is contained in:
@@ -31,37 +31,30 @@ export async function executeManageTroubleshoot(
|
||||
|
||||
logger.info('트러블슈팅 도구 호출', { action, userId: telegramUserId });
|
||||
|
||||
if (!env?.SESSION_KV || !telegramUserId) {
|
||||
if (!env?.DB || !telegramUserId) {
|
||||
return '🚫 트러블슈팅 기능을 사용할 수 없습니다.';
|
||||
}
|
||||
|
||||
const { getTroubleshootSession, saveTroubleshootSession, deleteTroubleshootSession } = await import('../agents/troubleshoot-agent');
|
||||
const { getTroubleshootSession, createTroubleshootSession, saveTroubleshootSession, deleteTroubleshootSession } = await import('../agents/troubleshoot-agent');
|
||||
|
||||
if (action === 'cancel') {
|
||||
await deleteTroubleshootSession(env.SESSION_KV, telegramUserId);
|
||||
await deleteTroubleshootSession(env.DB, telegramUserId);
|
||||
return '✅ 트러블슈팅 세션이 취소되었습니다.';
|
||||
}
|
||||
|
||||
// action === 'start'
|
||||
const existingSession = await getTroubleshootSession(env.SESSION_KV, telegramUserId);
|
||||
const existingSession = await getTroubleshootSession(env.DB, telegramUserId);
|
||||
|
||||
if (existingSession && existingSession.status !== 'completed') {
|
||||
return '이미 진행 중인 트러블슈팅 세션이 있습니다. 계속 진행해주세요.\n\n현재까지 파악된 정보:\n' +
|
||||
(existingSession.collectedInfo.category ? `• 분류: ${existingSession.collectedInfo.category}\n` : '') +
|
||||
(existingSession.collectedInfo.symptoms ? `• 증상: ${existingSession.collectedInfo.symptoms}\n` : '');
|
||||
(existingSession.collected_info.category ? `• 분류: ${existingSession.collected_info.category}\n` : '') +
|
||||
(existingSession.collected_info.symptoms ? `• 증상: ${existingSession.collected_info.symptoms}\n` : '');
|
||||
}
|
||||
|
||||
// Create new session
|
||||
const newSession = {
|
||||
telegramUserId,
|
||||
status: 'gathering' as const,
|
||||
collectedInfo: {},
|
||||
messages: [],
|
||||
createdAt: Date.now(),
|
||||
updatedAt: Date.now(),
|
||||
};
|
||||
const newSession = createTroubleshootSession(telegramUserId, 'gathering');
|
||||
|
||||
await saveTroubleshootSession(env.SESSION_KV, telegramUserId, newSession);
|
||||
await saveTroubleshootSession(env.DB, newSession);
|
||||
|
||||
logger.info('트러블슈팅 세션 시작', { userId: telegramUserId });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user