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:
kappa
2026-02-05 10:01:40 +09:00
parent d069e84efd
commit cb2bd48ad6

View File

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