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:
kappa
2026-02-05 10:57:55 +09:00
parent 5d8150e67c
commit de36978de4
6 changed files with 359 additions and 233 deletions

View File

@@ -6,7 +6,7 @@ import { createLogger } from './utils/logger';
import { metrics } from './utils/metrics';
import { getOpenAIUrl } from './utils/api-urls';
import { ERROR_MESSAGES } from './constants/messages';
import { getServerSession, processServerConsultation } from './agents/server-agent';
import { hasServerSession, processServerConsultation } from './agents/server-agent';
import { processTroubleshootConsultation, hasTroubleshootSession } from './agents/troubleshoot-agent';
import { processDomainConsultation, hasDomainSession } from './agents/domain-agent';
import { processDepositConsultation, hasDepositSession } from './agents/deposit-agent';
@@ -210,13 +210,11 @@ export async function generateOpenAIResponse(
// Check if server consultation session is active
if (telegramUserId && env.DB) {
try {
const session = await getServerSession(env.DB, telegramUserId);
const hasSession = await hasServerSession(env.DB, telegramUserId);
if (session && session.status !== 'completed') {
if (hasSession) {
logger.info('Active server session detected, routing to consultation', {
userId: telegramUserId,
status: session.status,
hasLastRecommendation: !!session.lastRecommendation
userId: telegramUserId
});
// Create callback for intermediate messages
@@ -229,7 +227,13 @@ export async function generateOpenAIResponse(
};
}
const result = await processServerConsultation(userMessage, session, env, sendIntermediateMessage);
const result = await processServerConsultation(
env.DB,
telegramUserId,
userMessage,
env,
{ sendIntermediateMessage }
);
// PASSTHROUGH: 무관한 메시지는 일반 처리로 전환
if (result !== '__PASSTHROUGH__') {