Commit Graph

14 Commits

Author SHA1 Message Date
kappa
e32e3c6a44 refactor: improve OpenAI service and tools
- Enhance OpenAI message types with tool_calls support
- Improve security validation and rate limiting
- Update utility tools and weather tool
- Minor fixes in deposit-agent and domain-register

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 20:26:31 +09:00
kappa
860e36a688 feat: add memory system and troubleshoot agent
Memory System:
- Add category-based memory storage (company, tech, role, location, server)
- Silent background saving via saveMemorySilently()
- Category-based overwrite (same category replaces old memory)
- Server-related pattern detection (AWS, GCP, k8s, traffic info)
- Memory management tool (list, delete)

Troubleshoot Agent:
- Session-based troubleshooting conversation (KV, 1h TTL)
- 20-year DevOps/SRE expert persona
- Support for server/infra, domain/DNS, code/deploy, network, database issues
- Internal tools: search_solution (Brave), lookup_docs (Context7)
- Auto-trigger on error-related keywords
- Session completion and cancellation support

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 14:28:22 +09:00
kappa
a2d05c82c3 feat: add Server Expert AI with search/docs tools for trend-aware recommendations
- Add server-agent.ts with 30-year senior architect persona
- Implement KV-based session management for multi-turn conversations
- Add search_trends (Brave Search) and lookup_framework_docs (Context7) tools
- Function Calling support with max 3 tool calls per request
- Auto-infer tech stack and expected users from use case/scale
- Prohibit competitor provider mentions (AWS, GCP, Azure, etc.)
- Simplify main AI system prompt, delegate complex logic to expert AI

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-26 14:15:15 +09:00
kappa
87c92e1ed1 refactor: migrate server provisioning to Cloud Orchestrator service
- Remove Queue-based server provisioning (moved to cloud-orchestrator)
- Add manage_server tool with Service Binding to Cloud Orchestrator
- Add CDN cache hit rate estimation based on tech_stack
- Always display bandwidth info (show "포함 범위 내" when no overage)
- Add language auto-detection (ko, ja, zh, en)
- Update system prompt to always call tools fresh
- Add Server System documentation to CLAUDE.md

BREAKING: Server provisioning now requires cloud-orchestrator service

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-26 12:26:21 +09:00
kappa
43419a8025 docs: update documentation and add server schema
- Update CLAUDE.md with server provisioning docs
- Add server tables to schema.sql (cloud_providers, instance_specs, etc.)
- Register manage_server tool in tools/index.ts
- Minor fixes to conversation-service and summary-service

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-24 21:41:14 +09:00
kappa
97d6aa2850 fix: critical P0+P1 issues for code quality score 9.0
P0 (Critical):
- api.ts: Add transaction rollback on INSERT failure in /api/deposit/deduct
  - Restores balance if transaction record fails to insert
  - Logs rollback success/failure for audit trail
  - Maintains data consistency despite D1's non-transactional nature

P1 (Important):
- summary-service.ts: Replace double type assertions with Type Guards
  - Add D1BufferedMessageRow, D1SummaryRow interfaces
  - Add isBufferedMessageRow, isSummaryRow type guards
  - Runtime validation with compile-time type safety
  - Remove all `as unknown as` patterns

- webhook.ts: Add integer range validation for callback queries
  - Add parseIntSafe() utility with min/max bounds
  - Validate domain registration price (0-10,000,000 KRW)
  - Prevent negative/overflow/NaN injection attacks

- search-tool.ts: Implement KV caching for translation API
  - Cache Korean→English translations for 24 hours
  - Use RATE_LIMIT_KV namespace with 'translate:' prefix
  - Reduce redundant OpenAI API calls for repeated queries

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-19 23:59:18 +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
4f68dd3ebb fix: critical security and data integrity improvements (P1/P2)
## P1 Critical Issues
- Add D1 batch result verification to prevent partial transaction failures
  * deposit-agent.ts: deposit confirmation and admin approval
  * domain-register.ts: domain registration payment
  * deposit-matcher.ts: SMS auto-matching
  * summary-service.ts: profile system updates
  * routes/api.ts: external API deposit deduction

- Remove internal error details from API responses
  * All 500 errors now return generic "Internal server error"
  * Detailed errors logged internally via console.error

- Enforce WEBHOOK_SECRET validation
  * Reject requests when WEBHOOK_SECRET is not configured
  * Prevent accidental production deployment without security

## P2 High Priority Issues
- Add SQL LIMIT parameter validation (1-100 range)
- Enforce CORS Origin header validation for /api/contact
- Optimize domain suggestion API calls (parallel processing)
  * 80% performance improvement for TLD price fetching
  * Individual error handling per TLD
- Add sensitive data masking in logs (user IDs)
  * New maskUserId() helper function
  * GDPR compliance for user privacy

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 21:53:18 +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
42ab702d1c feat: 도메인 시스템 개선 + 검색 한글→영문 번역
주요 변경:
- Domain Agent 제거, 코드 직접 처리로 전환
- suggest_domains: 등록 가능 도메인만 표시, 10개 미만 시 재시도
- search_web: 한글 검색어 자동 영문 번역 (GPT-4o-mini)
- WHOIS: raw 데이터 파싱으로 상세 정보 추출
- 가격 조회: API 필드명 수정 (register_krw → krw)
- 동적 도구 로딩 시스템 추가
- 문서 정리 및 업데이트

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 11:15:49 +09:00
kappa
254b5a041d fix: 에이전트 응답 그대로 전달하도록 시스템 프롬프트 수정
- manage_deposit, manage_domain 도구 결과를 가공 없이 전달
- 불필요한 추가 질문/멘트 방지

Deposit Agent (OpenAI) 프롬프트도 별도 업데이트:
- 동시 입금 요청 허용
- 즉시 실행 (확인 질문 금지)
- 응답 스타일 간결화

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-17 11:33:10 +09:00
kappa
363a0a504f feat: DuckDuckGo → Brave Search 교체 + 입금 알림 개선
## 검색 API 교체
- DuckDuckGo Instant Answer API → Brave Search API
- 실제 웹 검색 결과 반환 (제목, 설명, URL)
- Vault에 API 키 저장 (secret/brave-search)
- Free AI 플랜: 2,000 queries/월

## 시스템 프롬프트 개선
- 검색 도구 사용 조건 명시 (최신 정보, 실시간 가격 등)
- 도구 description에 트리거 키워드 추가

## 입금 알림 개선
- 자동 매칭 성공 시 사용자에게 Telegram 알림 전송
- tryAutoMatch() 반환값에 userId, amount 추가

## 문서 업데이트
- Function Calling Tools 테이블에 트리거 키워드 컬럼 추가
- AI 시스템 프롬프트 섹션 추가
- Deposit Agent 프롬프트 수정 방법 문서화
- 자동 알림 시스템 섹션 추가

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-17 10:25:27 +09:00
kappa
8b2ccf05b5 feat: 도메인 관리 기능 추가 (Domain Agent 연동)
- manage_domain Function Calling 도구 추가
- OpenAI Assistants API 기반 Domain Agent 연동
- Namecheap API 호출 (도메인 목록, 네임서버 관리 등)
- user_domains 테이블로 사용자별 도메인 권한 관리
- 타임스탬프 검증 비활성화 (WEBHOOK_SECRET으로 충분)
- CLAUDE.md 프로젝트 문서 추가

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 08:50:16 +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