kappa
3cfcb06f27
refactor: centralize auth middleware and standardize logging
...
1. API Key Middleware (api.ts)
- Create apiKeyAuth Hono middleware with timing-safe comparison
- Apply to /deposit/balance and /deposit/deduct routes
- Remove duplicate requireApiKey() calls from handlers
- Reduce ~15 lines of duplicated code
2. Logger Standardization (6 files, 27 replacements)
- webhook.ts: 2 console.error → logger
- message-handler.ts: 7 console → logger
- deposit-matcher.ts: 4 console → logger
- n8n-service.ts: 3 console.error → logger
- circuit-breaker.ts: 8 console → logger
- retry.ts: 3 console → logger
Benefits:
- Single point of auth change
- Structured logging with context
- Better observability in production
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-01-29 09:58:15 +09:00
kappa
a2cb4ce686
refactor: remove Workers AI as any with proper type definitions
...
- Add WorkersAIModel, WorkersAITextGenerationInput/Output types
- Remove `as any` from summary-service.ts (4 instances)
- Remove `as any` from bank-sms-parser.ts (3 instances)
- Remove `as any` from n8n-service.ts (2 instances)
- Add OpenAIResponse interface for API responses
Type-safe Workers AI calls with full IntelliSense support.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-01-19 23:42:17 +09:00
kappa
45e0677ab0
refactor: code quality improvements (P3)
...
## 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 >
2026-01-19 22:06:01 +09:00
kappa
ab6c9a2efa
refactor: 파일 분리 리팩토링 (routes, services, tools, utils)
...
아키텍처 개선:
- index.ts: 921줄 → 205줄 (77% 감소)
- openai-service.ts: 1,356줄 → 148줄 (89% 감소)
새로운 디렉토리 구조:
- src/routes/ - Webhook, API, Health check 핸들러
- webhook.ts (287줄)
- api.ts (318줄)
- health.ts (14줄)
- src/services/ - 비즈니스 로직
- bank-sms-parser.ts (143줄)
- deposit-matcher.ts (88줄)
- src/tools/ - Function Calling 도구 모듈화
- weather-tool.ts (37줄)
- search-tool.ts (156줄)
- domain-tool.ts (725줄)
- deposit-tool.ts (183줄)
- utility-tools.ts (60줄)
- index.ts (104줄) - 도구 레지스트리
- src/utils/ - 유틸리티 함수
- email-decoder.ts - Quoted-Printable 디코더
타입 에러 수정:
- routes/webhook.ts: text undefined 체크
- summary-service.ts: D1 타입 캐스팅
- summary-service.ts: Workers AI 타입 처리
- n8n-service.ts: Workers AI 타입 + 미사용 변수 제거
빌드 검증:
- TypeScript 타입 체크 통과
- Wrangler dev 로컬 빌드 성공
문서:
- REFACTORING_SUMMARY.md 추가
- ROUTE_ARCHITECTURE.md 추가
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2026-01-19 15:36:17 +09:00
kappa
1e71e035e7
Initial commit: Telegram bot with Cloudflare Workers
...
- OpenAI GPT-4o-mini with Function Calling
- Cloudflare D1 for user profiles and message buffer
- Sliding window (3 summaries max) for infinite context
- Tools: weather, search, time, calculator
- Workers AI fallback support
- Webhook security with rate limiting
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-01-14 13:00:44 +09:00