refactor: unify server-agent to new pattern
- Change field names to snake_case (user_id, collected_info, last_recommendation, created_at, updated_at, expires_at) - Extract system prompts to constants (SERVER_EXPERT_PROMPT, SERVER_REVIEW_PROMPT) - Add __PASSTHROUGH__/__SESSION_END__ marker support - Change handler signature to match other agents (db, userId, userMessage, env, options) - Add helper functions for consistency (createServerSession, isSessionExpired, addMessageToSession, hasServerSession) - Update saveSe rverSession signature to not need userId separately - Rename tools constant from serverExpertTools to serverExpertTools (camelCase) - Change AI call parameter order for consistency - Add performance logging - Update openai-service.ts routing to use hasServerSession - Update server-tool.ts to use new session creation helpers - Update message-handler.ts and api/chat.ts field references Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -664,7 +664,7 @@ export async function executeServerAction(
|
||||
switch (action) {
|
||||
case 'start_consultation': {
|
||||
// Import session functions
|
||||
const { saveServerSession } = await import('../agents/server-agent');
|
||||
const { createServerSession, saveServerSession } = await import('../agents/server-agent');
|
||||
|
||||
if (!telegramUserId) {
|
||||
return '🚫 사용자 인증이 필요합니다.';
|
||||
@@ -674,16 +674,8 @@ export async function executeServerAction(
|
||||
return '🚫 세션 저장소가 설정되지 않았습니다.';
|
||||
}
|
||||
|
||||
const session: import('../types').ServerSession = {
|
||||
telegramUserId,
|
||||
status: 'gathering',
|
||||
collectedInfo: {},
|
||||
messages: [],
|
||||
createdAt: Date.now(),
|
||||
updatedAt: Date.now(),
|
||||
};
|
||||
|
||||
await saveServerSession(env.DB, telegramUserId, session);
|
||||
const session = createServerSession(telegramUserId, 'gathering');
|
||||
await saveServerSession(env.DB, session);
|
||||
|
||||
logger.info('상담 세션 생성', { userId: maskUserId(telegramUserId) });
|
||||
|
||||
@@ -691,7 +683,7 @@ export async function executeServerAction(
|
||||
}
|
||||
|
||||
case 'continue_consultation': {
|
||||
const { getServerSession, processServerConsultation } = await import('../agents/server-agent');
|
||||
const { processServerConsultation } = await import('../agents/server-agent');
|
||||
|
||||
if (!telegramUserId) {
|
||||
return '🚫 사용자 인증이 필요합니다.';
|
||||
@@ -705,12 +697,7 @@ export async function executeServerAction(
|
||||
return '🚫 메시지가 필요합니다.';
|
||||
}
|
||||
|
||||
const session = await getServerSession(env.DB, telegramUserId);
|
||||
if (!session) {
|
||||
return '세션이 만료되었습니다. 다시 시작하려면 "서버 추천"이라고 말씀해주세요.';
|
||||
}
|
||||
|
||||
const result = await processServerConsultation(args.message, session, env);
|
||||
const result = await processServerConsultation(env.DB, telegramUserId, args.message, env);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -771,30 +758,24 @@ export async function executeServerAction(
|
||||
// 세션에 추천 결과 저장 (선택 기능 활성화)
|
||||
if (telegramUserId && env?.DB && recommendationData.recommendations && recommendationData.recommendations.length > 0) {
|
||||
try {
|
||||
const { getServerSession, saveServerSession } = await import('../agents/server-agent');
|
||||
const { getServerSession, saveServerSession, createServerSession } = await import('../agents/server-agent');
|
||||
|
||||
// 기존 세션 조회 또는 새로 생성
|
||||
let session = await getServerSession(env.DB, telegramUserId);
|
||||
|
||||
if (!session) {
|
||||
// 세션이 없으면 새로 생성
|
||||
session = {
|
||||
telegramUserId,
|
||||
status: 'selecting',
|
||||
collectedInfo: {
|
||||
useCase: use_case,
|
||||
scale: expected_users <= 50 ? 'personal' : 'business',
|
||||
expectedConcurrent: expected_users,
|
||||
},
|
||||
messages: [],
|
||||
createdAt: Date.now(),
|
||||
updatedAt: Date.now(),
|
||||
session = createServerSession(telegramUserId, 'selecting');
|
||||
session.collected_info = {
|
||||
useCase: use_case,
|
||||
scale: expected_users <= 50 ? 'personal' : 'business',
|
||||
expectedConcurrent: expected_users,
|
||||
};
|
||||
logger.info('새 세션 생성 (추천 결과 저장용)', { userId: telegramUserId });
|
||||
}
|
||||
|
||||
// lastRecommendation 저장
|
||||
session.lastRecommendation = {
|
||||
// last_recommendation 저장
|
||||
session.last_recommendation = {
|
||||
recommendations: recommendationData.recommendations.slice(0, 3).map(rec => ({
|
||||
pricing_id: rec.server.id,
|
||||
plan_name: rec.server.instance_name,
|
||||
@@ -821,17 +802,17 @@ export async function executeServerAction(
|
||||
score: rec.score,
|
||||
max_users: rec.estimated_capacity?.max_concurrent_users || 0
|
||||
})),
|
||||
createdAt: Date.now()
|
||||
created_at: Date.now()
|
||||
};
|
||||
|
||||
// status를 'selecting'으로 변경
|
||||
session.status = 'selecting';
|
||||
session.updatedAt = Date.now();
|
||||
session.updated_at = Date.now();
|
||||
|
||||
await saveServerSession(env.DB, telegramUserId, session);
|
||||
await saveServerSession(env.DB, session);
|
||||
logger.info('추천 결과 세션 저장 완료', {
|
||||
userId: telegramUserId,
|
||||
recommendationCount: session.lastRecommendation.recommendations.length,
|
||||
recommendationCount: session.last_recommendation.recommendations.length,
|
||||
status: session.status
|
||||
});
|
||||
} catch (sessionError) {
|
||||
|
||||
Reference in New Issue
Block a user