feat: add domain tool execution dispatcher
- Add executeDomainToolCall function - Integrate with existing domain-tool.ts functions - Map AI tool calls to domain actions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
import type { Env, DomainSession, DomainSessionStatus } from '../types';
|
||||
import { createLogger } from '../utils/logger';
|
||||
import { executeDomainAction, executeSuggestDomains } from '../tools/domain-tool';
|
||||
|
||||
const logger = createLogger('domain-agent');
|
||||
|
||||
@@ -463,6 +464,120 @@ ${JSON.stringify(session.collected_info, null, 2)}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 도메인 도구 실행 디스패처
|
||||
*
|
||||
* Domain Agent AI가 호출한 tool을 실제 domain-tool.ts 함수로 매핑
|
||||
*
|
||||
* @param toolName - 도구 이름
|
||||
* @param args - 도구 인자
|
||||
* @param env - Environment
|
||||
* @param userId - Telegram User ID
|
||||
* @param db - D1 Database
|
||||
* @returns 도구 실행 결과 (텍스트)
|
||||
*/
|
||||
export async function executeDomainToolCall(
|
||||
toolName: string,
|
||||
args: Record<string, unknown>,
|
||||
env: Env,
|
||||
userId: string,
|
||||
db: D1Database
|
||||
): Promise<string> {
|
||||
logger.info('도메인 도구 실행', { toolName, args });
|
||||
|
||||
// 사용자 소유 도메인 조회 (권한 검증용)
|
||||
let allowedDomains: string[] = [];
|
||||
let userIdNum: number | undefined;
|
||||
|
||||
try {
|
||||
const user = await db.prepare(
|
||||
'SELECT id FROM users WHERE telegram_id = ?'
|
||||
).bind(userId).first<{ id: number }>();
|
||||
|
||||
if (user) {
|
||||
userIdNum = user.id;
|
||||
const domains = await db.prepare(
|
||||
'SELECT domain FROM user_domains WHERE user_id = ? AND verified = 1'
|
||||
).bind(user.id).all<{ domain: string }>();
|
||||
allowedDomains = domains.results?.map(d => d.domain) || [];
|
||||
logger.info('소유 도메인 조회', { userDomains: allowedDomains });
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('도메인 권한 조회 실패', error as Error, { userId });
|
||||
// 계속 진행 (읽기 작업은 가능)
|
||||
}
|
||||
|
||||
switch (toolName) {
|
||||
case 'check_domain':
|
||||
return executeDomainAction(
|
||||
'check',
|
||||
{ domain: args.domain as string },
|
||||
allowedDomains,
|
||||
env,
|
||||
userId,
|
||||
db,
|
||||
userIdNum
|
||||
);
|
||||
|
||||
case 'search_suggestions':
|
||||
return executeSuggestDomains(
|
||||
{ keywords: args.keywords as string },
|
||||
env
|
||||
);
|
||||
|
||||
case 'get_whois':
|
||||
return executeDomainAction(
|
||||
'whois',
|
||||
{ domain: args.domain as string },
|
||||
allowedDomains,
|
||||
env,
|
||||
userId,
|
||||
db,
|
||||
userIdNum
|
||||
);
|
||||
|
||||
case 'get_price':
|
||||
return executeDomainAction(
|
||||
'price',
|
||||
{ tld: args.tld as string },
|
||||
allowedDomains,
|
||||
env,
|
||||
userId,
|
||||
db,
|
||||
userIdNum
|
||||
);
|
||||
|
||||
case 'register_domain':
|
||||
return executeDomainAction(
|
||||
'register',
|
||||
{ domain: args.domain as string },
|
||||
allowedDomains,
|
||||
env,
|
||||
userId,
|
||||
db,
|
||||
userIdNum
|
||||
);
|
||||
|
||||
case 'set_nameservers':
|
||||
return executeDomainAction(
|
||||
'set_ns',
|
||||
{
|
||||
domain: args.domain as string,
|
||||
nameservers: args.nameservers as string[]
|
||||
},
|
||||
allowedDomains,
|
||||
env,
|
||||
userId,
|
||||
db,
|
||||
userIdNum
|
||||
);
|
||||
|
||||
default:
|
||||
logger.warn('알 수 없는 도메인 도구', { toolName });
|
||||
return `❌ 알 수 없는 도구: ${toolName}`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 도메인 추천 상담 처리 (메인 함수)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user