refactor: convert domain-tool to agent trigger
- Modify executeManageDomain to delegate to domain agent - Add buildDomainMessage helper for action-to-message conversion - Keep internal functions for agent tool execution Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -837,54 +837,53 @@ export async function executeManageDomain(
|
||||
telegramUserId?: string,
|
||||
db?: D1Database
|
||||
): Promise<string> {
|
||||
const { action, domain, nameservers, tld } = args;
|
||||
logger.info('시작', { action, domain, userId: maskUserId(telegramUserId), hasDb: !!db });
|
||||
logger.info('manage_domain 시작 (에이전트 위임)', { action: args.action, userId: maskUserId(telegramUserId) });
|
||||
|
||||
// 소유권 검증 (DB 조회)
|
||||
if (!telegramUserId || !db) {
|
||||
logger.info('실패: telegramUserId 또는 db 없음');
|
||||
return '🚫 도메인 관리 권한이 없습니다.';
|
||||
if (!db || !telegramUserId || !env) {
|
||||
return '❌ 도메인 관리 기능을 사용할 수 없습니다.';
|
||||
}
|
||||
|
||||
let userDomains: string[] = [];
|
||||
let userId: number | undefined;
|
||||
try {
|
||||
const user = await db.prepare(
|
||||
'SELECT id FROM users WHERE telegram_id = ?'
|
||||
).bind(telegramUserId).first<{ id: number }>();
|
||||
// Import processDomainConsultation dynamically to avoid circular deps
|
||||
const { processDomainConsultation } = await import('../agents/domain-agent');
|
||||
|
||||
if (!user) {
|
||||
return '🚫 도메인 관리 권한이 없습니다.';
|
||||
}
|
||||
userId = user.id;
|
||||
// Convert the action + args to a natural language message for the agent
|
||||
const userMessage = buildDomainMessage(args);
|
||||
logger.info('도메인 메시지 변환', { message: userMessage });
|
||||
|
||||
// 사용자 소유 도메인 전체 목록 조회
|
||||
const domains = await db.prepare(
|
||||
'SELECT domain FROM user_domains WHERE user_id = ? AND verified = 1'
|
||||
).bind(user.id).all<{ domain: string }>();
|
||||
userDomains = domains.results?.map(d => d.domain) || [];
|
||||
logger.info('소유 도메인', { userDomains });
|
||||
} catch (error) {
|
||||
logger.error('DB 오류', error as Error);
|
||||
return '🚫 권한 확인 중 오류가 발생했습니다.';
|
||||
// Delegate to domain agent
|
||||
const response = await processDomainConsultation(db, telegramUserId, userMessage, env);
|
||||
|
||||
// If passthrough, the message wasn't domain-related
|
||||
if (response === '__PASSTHROUGH__') {
|
||||
return '도메인 관련 요청을 이해하지 못했습니다. 다시 말씀해주세요.';
|
||||
}
|
||||
|
||||
// 코드로 직접 처리 (Agent 없이)
|
||||
try {
|
||||
const result = await executeDomainAction(
|
||||
action,
|
||||
{ domain, nameservers, tld },
|
||||
userDomains,
|
||||
env,
|
||||
telegramUserId,
|
||||
db,
|
||||
userId
|
||||
);
|
||||
logger.info('완료', { result: result?.slice(0, 100) });
|
||||
return result;
|
||||
} catch (error) {
|
||||
logger.error('도메인 관리 오류', error as Error);
|
||||
return '🚫 도메인 관리 중 오류가 발생했습니다. 잠시 후 다시 시도해주세요.';
|
||||
return response;
|
||||
}
|
||||
|
||||
// Helper to convert action args to natural message
|
||||
function buildDomainMessage(args: { action: string; domain?: string; nameservers?: string[]; tld?: string }): string {
|
||||
switch (args.action) {
|
||||
case 'check':
|
||||
return `${args.domain} 도메인 가용성 확인해줘`;
|
||||
case 'whois':
|
||||
return `${args.domain} WHOIS 조회해줘`;
|
||||
case 'price':
|
||||
return `${args.tld || args.domain || 'com'} 가격 알려줘`;
|
||||
case 'cheapest':
|
||||
return '가장 저렴한 TLD 목록 보여줘';
|
||||
case 'list':
|
||||
return '내 도메인 목록 보여줘';
|
||||
case 'info':
|
||||
return `${args.domain} 정보 보여줘`;
|
||||
case 'get_ns':
|
||||
return `${args.domain} 네임서버 조회해줘`;
|
||||
case 'set_ns':
|
||||
return `${args.domain} 네임서버를 ${args.nameservers?.join(', ')}로 변경해줘`;
|
||||
case 'register':
|
||||
return `${args.domain} 등록해줘`;
|
||||
default:
|
||||
return `도메인 ${args.action} 작업`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user