diff --git a/troubleshooting/250826_happybell80_frontend_rb8001_채팅연결_계획.md b/troubleshooting/250826_happybell80_frontend_rb8001_채팅연결_계획.md new file mode 100644 index 0000000..ef229b9 --- /dev/null +++ b/troubleshooting/250826_happybell80_frontend_rb8001_채팅연결_계획.md @@ -0,0 +1,237 @@ +# Frontend-rb8001 채팅 연결 문제 해결 계획 + +## 작성일: 2025-08-26 +## 작성자: happybell80 +## 상태: 계획 수립 완료 +## 관련 서비스: frontend-customer, robeing-gateway, rb8001 + +--- + +## 1. 문제 상황 + +### 1.1 현재 시스템 플로우 +``` +Frontend(React) → Gateway(8100) → rb8001(8001) + ↓ ↓ ↓ + /api/chat /api/message 404 Error +``` + +### 1.2 핵심 문제 +- **Frontend**: `/api/chat` 엔드포인트로 요청 전송 +- **Gateway**: `/api/chat` → `/api/message`로 프록시 (정상 구현됨) +- **rb8001**: `/api/message` 엔드포인트 없음 (404 반환) +- **rb10508_micro**: `/api/message` 엔드포인트 있음 (정상 작동) + +### 1.3 서버 확인 결과 + +#### 51123 서버 (Gateway) +- Gateway 라우팅: `/stats`만 rb8001로 프록시 중 +- 사용자 매핑: happybell80 → rb8001 정상 매핑 +- 문제점: robeing_id가 "undefined"로 전달됨 + +#### 51124 서버 (rb8001) +- rb8001은 Docker 컨테이너가 아닌 Python 프로세스로 실행 중 (PID 1336125) +- 포트 8001 정상 리스닝 +- `/api/message`, `/api/chat` 엔드포인트 없음 +- 사용 가능: `/complete`, `/api/slack/events` 등 + +--- + +## 2. 해결 방안 분석 + +### 방안 A: rb8001에 /api/message 엔드포인트 추가 ✅ (선택) +**장점:** +- rb10508_micro와 일관성 유지 +- Gateway 수정 불필요 +- 다른 사용자/서비스 영향 없음 + +**단점:** +- rb8001 코드 수정 필요 + +### 방안 B: Gateway에서 rb8001용 특별 처리 +**장점:** +- rb8001 수정 불필요 + +**단점:** +- Gateway 복잡도 증가 +- 로빙별 분기 처리 필요 +- 유지보수 어려움 + +### 방안 C: Frontend에서 로빙별 다른 엔드포인트 호출 +**장점:** +- 백엔드 수정 최소화 + +**단점:** +- Frontend 복잡도 증가 +- 로빙 정보 사전 필요 +- 확장성 떨어짐 + +--- + +## 3. 구현 계획 (방안 A) + +### 3.1 rb8001/main.py 수정 내용 + +```python +# 1. Import 추가 (파일 상단) +from pydantic import BaseModel +from typing import Optional, Dict + +# 2. MessageRequest 모델 정의 +class MessageRequest(BaseModel): + text: str + user_id: Optional[str] = None + context: Optional[Dict] = {} + channel_id: Optional[str] = None + +# 3. /api/message 엔드포인트 추가 +@app.post("/api/message") +async def message_endpoint(request: MessageRequest): + """ + Gateway/Frontend 메시지 처리 엔드포인트 + rb10508_micro와 호환되는 인터페이스 제공 + """ + try: + # 기존 _call_internal_llm 활용 + result = await router._call_internal_llm( + message=request.text, + user_id=request.user_id or "web_user", + task_type="chat", + context=request.context, + channel="web" # 웹 채팅 채널로 구분 + ) + + # Frontend가 기대하는 응답 형식 + return { + "response": result.get("content", ""), + "robeing_id": settings.ROBEING_ID, + "timestamp": datetime.now().isoformat(), + "success": result.get("success", False) + } + + except Exception as e: + logger.error(f"Message endpoint error: {e}") + raise HTTPException(status_code=500, detail=str(e)) +``` + +### 3.2 추가 고려사항 + +#### 대화 저장 로직 +```python +# ChromaDB와 PostgreSQL에 대화 저장 +await router._save_conversation( + message=request.text, + response=result.get("content", ""), + user_id=request.user_id, + channel="web" +) +``` + +#### 사용자 레벨/스탯 조회 +```python +# DB에서 실제 로빙 스탯 조회 +stats = await router.get_robeing_stats() +response["level"] = stats.get("level", 1) +``` + +--- + +## 4. 작업 단계 + +### 4.1 구현 순서 +1. **코드 작성** (10분) + - MessageRequest 모델 정의 + - /api/message 엔드포인트 구현 + - 응답 형식 맞춤 + +2. **로컬 테스트** (5분) + ```bash + # 직접 엔드포인트 테스트 + curl -X POST http://localhost:8001/api/message \ + -H "Content-Type: application/json" \ + -d '{"text":"안녕하세요","user_id":"test"}' + ``` + +3. **통합 테스트** (5분) + ```bash + # Gateway 경유 테스트 + curl -X POST http://localhost:8100/api/chat \ + -H "Authorization: Bearer [TOKEN]" \ + -d '{"text":"안녕하세요"}' + ``` + +4. **배포** (5분) + - Git commit & push + - 서버에서 프로세스 재시작 + +### 4.2 검증 방법 +1. Frontend 로그인 (happybell80) +2. 채팅 입력 +3. 응답 확인 +4. rb8001 로그 확인: `tail -f rb8001.log` + +--- + +## 5. 예상 결과 + +### 5.1 정상 플로우 +``` +Frontend → POST /api/chat {"text":"안녕"} + ↓ +Gateway(8100) → happybell80 → rb8001 매핑 + ↓ +rb8001(8001) → /api/message 처리 + ↓ +응답: {"response":"안녕하세요! 무엇을 도와드릴까요?"} +``` + +### 5.2 모니터링 포인트 +- Gateway 로그: 라우팅 성공 +- rb8001 로그: 메시지 처리 +- ChromaDB: 대화 저장 +- PostgreSQL: conversation_logs 기록 + +--- + +## 6. 리스크 및 대응 + +### 6.1 잠재 이슈 +1. **타입 불일치**: MessageRequest 필드 검증 +2. **인증 문제**: JWT 토큰 처리 +3. **성능**: 동시 요청 처리 + +### 6.2 롤백 계획 +- rb8001 코드 git revert +- 프로세스 재시작 + +--- + +## 7. 향후 개선사항 + +1. **통일된 API 스펙 정의** + - OpenAPI/Swagger 문서화 + - 모든 로빙 서비스 표준화 + +2. **헬스체크 강화** + - 각 엔드포인트 가용성 체크 + - 자동 장애 감지 + +3. **로깅 개선** + - 요청/응답 상세 로깅 + - 성능 메트릭 수집 + +4. **테스트 자동화** + - E2E 테스트 스크립트 + - CI/CD 파이프라인 통합 + +--- + +## 8. 참고 문서 + +- 250826_frontend_rb8001_chat_endpoint_missing.md +- 250820_happybell80_사용자별로빙동적할당구현.md +- 250809_happybell80_robing-gateway구현.md + +--- + +*작성 완료: 2025-08-26 14:00* \ No newline at end of file