## Type Safety
- Add zod runtime validation for external API responses
* Namecheap API responses (domain-register.ts)
* n8n webhook responses (n8n-service.ts)
* User request bodies (routes/api.ts)
* Replaced unsafe type assertions with safeParse()
* Proper error handling and logging
## Dead Code Removal
- Remove unused callDepositAgent function (127 lines)
* Legacy Assistants API code no longer needed
* Now using direct code execution
* File reduced from 469 → 345 lines (26.4% reduction)
## Configuration Management
- Extract hardcoded URLs to environment variables
* Added 7 new vars in wrangler.toml:
OPENAI_API_BASE, NAMECHEAP_API_URL, WHOIS_API_URL,
CONTEXT7_API_BASE, BRAVE_API_BASE, WTTR_IN_URL, HOSTING_SITE_URL
* Updated Env interface in types.ts
* All URLs have fallback to current production values
* Enables environment-specific configuration (dev/staging/prod)
## Dependencies
- Add zod 4.3.5 for runtime type validation
## Files Modified
- Configuration: wrangler.toml, types.ts, package.json
- Services: 11 TypeScript files with URL/validation updates
- Total: 15 files, +196/-189 lines
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
114 lines
2.3 KiB
TypeScript
114 lines
2.3 KiB
TypeScript
export interface Env {
|
|
DB: D1Database;
|
|
AI: Ai;
|
|
BOT_TOKEN: string;
|
|
WEBHOOK_SECRET: 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;
|
|
}
|