feat: add domain session routing to openai-service
- Import domain agent functions - Add domain session check before main AI processing - Route to domain agent when session exists - Handle __PASSTHROUGH__ for non-domain messages Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import { getOpenAIUrl } from './utils/api-urls';
|
|||||||
import { ERROR_MESSAGES } from './constants/messages';
|
import { ERROR_MESSAGES } from './constants/messages';
|
||||||
import { getServerSession, processServerConsultation } from './agents/server-agent';
|
import { getServerSession, processServerConsultation } from './agents/server-agent';
|
||||||
import { getTroubleshootSession, processTroubleshoot } from './agents/troubleshoot-agent';
|
import { getTroubleshootSession, processTroubleshoot } from './agents/troubleshoot-agent';
|
||||||
|
import { processDomainConsultation, hasDomainSession } from './agents/domain-agent';
|
||||||
import { sendMessage } from './telegram';
|
import { sendMessage } from './telegram';
|
||||||
|
|
||||||
const logger = createLogger('openai');
|
const logger = createLogger('openai');
|
||||||
@@ -263,6 +264,29 @@ export async function generateOpenAIResponse(
|
|||||||
logger.error('Troubleshoot session check failed, continuing with normal flow', error as Error);
|
logger.error('Troubleshoot session check failed, continuing with normal flow', error as Error);
|
||||||
// Continue with normal flow if session check fails
|
// Continue with normal flow if session check fails
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if domain consultation session is active
|
||||||
|
try {
|
||||||
|
const hasDomainSess = await hasDomainSession(env.DB, telegramUserId);
|
||||||
|
|
||||||
|
if (hasDomainSess) {
|
||||||
|
logger.info('도메인 세션 감지, 도메인 에이전트로 라우팅', {
|
||||||
|
userId: telegramUserId
|
||||||
|
});
|
||||||
|
const domainResponse = await processDomainConsultation(env.DB, telegramUserId, userMessage, env);
|
||||||
|
|
||||||
|
// PASSTHROUGH: 무관한 메시지는 일반 처리로 전환
|
||||||
|
if (domainResponse !== '__PASSTHROUGH__') {
|
||||||
|
return domainResponse;
|
||||||
|
}
|
||||||
|
// Continue to normal flow below
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Domain session check failed, continuing with normal flow', error as Error, {
|
||||||
|
telegramUserId
|
||||||
|
});
|
||||||
|
// Continue with normal flow if session check fails
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!env.OPENAI_API_KEY) {
|
if (!env.OPENAI_API_KEY) {
|
||||||
|
|||||||
Reference in New Issue
Block a user