Security: - Add token+secret auth to /setup-webhook and /webhook-info endpoints - Disable /api/test in production environment (ENVIRONMENT=production) Performance: - Add retryWithBackoff to weather-tool (maxRetries: 2) - Add KV caching to executeLookupDocs (1h TTL) Code Quality: - Centralize error messages in src/constants/messages.ts - Update 5 files to use centralized error constants Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
352 lines
6.9 KiB
TypeScript
352 lines
6.9 KiB
TypeScript
export interface Env {
|
|
DB: D1Database;
|
|
AI: Ai;
|
|
BOT_TOKEN: string;
|
|
WEBHOOK_SECRET: string;
|
|
ENVIRONMENT?: string;
|
|
SUMMARY_THRESHOLD?: string;
|
|
MAX_SUMMARIES_PER_USER?: string;
|
|
N8N_WEBHOOK_URL?: string;
|
|
OPENAI_API_KEY?: string;
|
|
NAMECHEAP_API_KEY?: string;
|
|
NAMECHEAP_API_KEY_INTERNAL?: string;
|
|
DOMAIN_OWNER_ID?: string;
|
|
DEPOSIT_ADMIN_ID?: string;
|
|
BRAVE_API_KEY?: string;
|
|
DEPOSIT_API_SECRET?: string;
|
|
OPENAI_API_BASE?: string;
|
|
NAMECHEAP_API_URL?: string;
|
|
WHOIS_API_URL?: string;
|
|
CONTEXT7_API_BASE?: string;
|
|
BRAVE_API_BASE?: string;
|
|
WTTR_IN_URL?: string;
|
|
HOSTING_SITE_URL?: string;
|
|
RATE_LIMIT_KV: KVNamespace;
|
|
}
|
|
|
|
export interface IntentAnalysis {
|
|
action: 'chat' | 'n8n';
|
|
type?: string;
|
|
confidence: number;
|
|
}
|
|
|
|
export interface N8nResponse {
|
|
reply?: string;
|
|
error?: string;
|
|
}
|
|
|
|
export interface TelegramUpdate {
|
|
update_id: number;
|
|
message?: TelegramMessage;
|
|
callback_query?: CallbackQuery;
|
|
}
|
|
|
|
export interface CallbackQuery {
|
|
id: string;
|
|
from: TelegramUser;
|
|
message?: TelegramMessage;
|
|
chat_instance: string;
|
|
data?: string;
|
|
}
|
|
|
|
export interface TelegramMessage {
|
|
message_id: number;
|
|
from: TelegramUser;
|
|
chat: TelegramChat;
|
|
date: number;
|
|
text?: string;
|
|
}
|
|
|
|
export interface TelegramUser {
|
|
id: number;
|
|
is_bot: boolean;
|
|
first_name: string;
|
|
last_name?: string;
|
|
username?: string;
|
|
}
|
|
|
|
export interface TelegramChat {
|
|
id: number;
|
|
type: string;
|
|
}
|
|
|
|
export interface BufferedMessage {
|
|
id: number;
|
|
role: 'user' | 'bot';
|
|
message: string;
|
|
created_at: string;
|
|
}
|
|
|
|
export interface Summary {
|
|
id: number;
|
|
generation: number;
|
|
summary: string;
|
|
message_count: number;
|
|
created_at: string;
|
|
}
|
|
|
|
export interface ConversationContext {
|
|
previousSummary: Summary | null; // 최신 요약 (호환성 유지)
|
|
summaries: Summary[]; // 전체 요약 (최대 3개, 최신순)
|
|
recentMessages: BufferedMessage[];
|
|
totalMessages: number;
|
|
}
|
|
|
|
// Cloudflare Email Workers 타입
|
|
export interface EmailMessage {
|
|
from: string;
|
|
to: string;
|
|
headers: Headers;
|
|
raw: ReadableStream;
|
|
rawSize: number;
|
|
setReject(reason: string): void;
|
|
forward(to: string): Promise<void>;
|
|
}
|
|
|
|
// 은행 알림 파싱 결과
|
|
export interface BankNotification {
|
|
bankName: string;
|
|
depositorName: string;
|
|
amount: number;
|
|
balanceAfter?: number;
|
|
transactionTime?: Date;
|
|
rawMessage: string;
|
|
}
|
|
|
|
// Namecheap API 응답 타입
|
|
export interface NamecheapPriceResponse {
|
|
tld: string;
|
|
krw: number;
|
|
usd?: number;
|
|
register_krw?: number;
|
|
renew_krw?: number;
|
|
transfer_krw?: number;
|
|
}
|
|
|
|
export interface NamecheapDomainInfo {
|
|
name: string;
|
|
created: string;
|
|
expires: string;
|
|
is_expired: boolean;
|
|
auto_renew: boolean;
|
|
is_locked: boolean;
|
|
whois_guard: boolean;
|
|
nameservers?: string[];
|
|
}
|
|
|
|
export interface NamecheapCheckResult {
|
|
[domain: string]: boolean;
|
|
}
|
|
|
|
export interface NamecheapDomainListItem {
|
|
name: string;
|
|
created: string;
|
|
expires: string;
|
|
is_expired: boolean;
|
|
auto_renew: boolean;
|
|
is_locked: boolean;
|
|
whois_guard: boolean;
|
|
}
|
|
|
|
// Function Calling 인자 타입
|
|
export interface ManageDomainArgs {
|
|
action: 'register' | 'check' | 'whois' | 'list' | 'info' | 'get_ns' | 'set_ns' | 'price' | 'cheapest';
|
|
domain?: string;
|
|
nameservers?: string[];
|
|
tld?: string;
|
|
}
|
|
|
|
export interface ManageDepositArgs {
|
|
action: 'balance' | 'account' | 'request' | 'history' | 'cancel' | 'pending' | 'confirm' | 'reject';
|
|
depositor_name?: string;
|
|
amount?: number;
|
|
transaction_id?: number;
|
|
limit?: number;
|
|
}
|
|
|
|
export interface SuggestDomainsArgs {
|
|
keywords: string;
|
|
}
|
|
|
|
export interface SearchWebArgs {
|
|
query: string;
|
|
}
|
|
|
|
export interface LookupDocsArgs {
|
|
library: string;
|
|
query: string;
|
|
}
|
|
|
|
// Deposit Agent 결과 타입
|
|
export interface DepositBalanceResult {
|
|
balance: number;
|
|
formatted: string;
|
|
}
|
|
|
|
export interface DepositAccountInfoResult {
|
|
bank: string;
|
|
account: string;
|
|
holder: string;
|
|
instruction: string;
|
|
}
|
|
|
|
export interface DepositRequestResult {
|
|
success: boolean;
|
|
auto_matched: boolean;
|
|
transaction_id: number;
|
|
amount: number;
|
|
depositor_name: string;
|
|
status?: string;
|
|
new_balance?: number;
|
|
message: string;
|
|
account_info?: {
|
|
bank: string;
|
|
account: string;
|
|
holder: string;
|
|
};
|
|
}
|
|
|
|
export interface DepositTransaction {
|
|
id: number;
|
|
type: string;
|
|
amount: number;
|
|
status: string;
|
|
depositor_name: string;
|
|
description: string | null;
|
|
created_at: string;
|
|
confirmed_at: string | null;
|
|
}
|
|
|
|
export interface DepositTransactionsResult {
|
|
transactions: DepositTransaction[];
|
|
message?: string;
|
|
}
|
|
|
|
export interface DepositCancelResult {
|
|
success: boolean;
|
|
transaction_id: number;
|
|
message: string;
|
|
}
|
|
|
|
export interface DepositPendingItem {
|
|
id: number;
|
|
amount: number;
|
|
depositor_name: string;
|
|
created_at: string;
|
|
user: string;
|
|
}
|
|
|
|
export interface DepositPendingResult {
|
|
pending: DepositPendingItem[];
|
|
message?: string;
|
|
}
|
|
|
|
export interface DepositConfirmResult {
|
|
success: boolean;
|
|
transaction_id: number;
|
|
amount: number;
|
|
message: string;
|
|
}
|
|
|
|
export interface DepositRejectResult {
|
|
success: boolean;
|
|
transaction_id: number;
|
|
message: string;
|
|
}
|
|
|
|
export interface DepositErrorResult {
|
|
error: string;
|
|
}
|
|
|
|
export type DepositFunctionResult =
|
|
| DepositBalanceResult
|
|
| DepositAccountInfoResult
|
|
| DepositRequestResult
|
|
| DepositTransactionsResult
|
|
| DepositCancelResult
|
|
| DepositPendingResult
|
|
| DepositConfirmResult
|
|
| DepositRejectResult
|
|
| DepositErrorResult;
|
|
|
|
// Brave Search API 응답 타입
|
|
export interface BraveSearchResult {
|
|
title: string;
|
|
description: string;
|
|
url: string;
|
|
}
|
|
|
|
export interface BraveSearchResponse {
|
|
web?: {
|
|
results: BraveSearchResult[];
|
|
};
|
|
}
|
|
|
|
// OpenAI API 응답 타입
|
|
export interface OpenAIMessage {
|
|
role: string;
|
|
content: string;
|
|
}
|
|
|
|
export interface OpenAIChoice {
|
|
message: OpenAIMessage;
|
|
}
|
|
|
|
export interface OpenAIResponse {
|
|
choices?: OpenAIChoice[];
|
|
}
|
|
|
|
// Context7 API 응답 타입
|
|
export interface Context7Library {
|
|
id: string;
|
|
name: string;
|
|
}
|
|
|
|
export interface Context7SearchResponse {
|
|
libraries?: Context7Library[];
|
|
}
|
|
|
|
export interface Context7DocsResponse {
|
|
context?: string;
|
|
content?: string;
|
|
message?: string;
|
|
error?: string;
|
|
}
|
|
|
|
// Telegram Inline Keyboard 데이터
|
|
export interface DomainRegisterKeyboardData {
|
|
type: 'domain_register';
|
|
domain: string;
|
|
price: number;
|
|
}
|
|
|
|
export type KeyboardData = DomainRegisterKeyboardData;
|
|
|
|
// Workers AI Types (from worker-configuration.d.ts)
|
|
export type WorkersAIModel =
|
|
| '@cf/meta/llama-3.1-8b-instruct'
|
|
| '@cf/meta/llama-3.2-3b-instruct'
|
|
| '@cf/meta/llama-3-8b-instruct';
|
|
|
|
export interface WorkersAIMessage {
|
|
role: 'system' | 'user' | 'assistant';
|
|
content: string;
|
|
}
|
|
|
|
export interface WorkersAITextGenerationInput {
|
|
prompt?: string;
|
|
messages?: WorkersAIMessage[];
|
|
max_tokens?: number;
|
|
temperature?: number;
|
|
stream?: boolean;
|
|
}
|
|
|
|
export interface WorkersAITextGenerationOutput {
|
|
response?: string;
|
|
usage?: {
|
|
prompt_tokens: number;
|
|
completion_tokens: number;
|
|
total_tokens: number;
|
|
};
|
|
}
|