feat(backend): 협상 채팅(chat) API + agent 위임

- /v1/negotiation/sessions/{id}/chat/{init,messages,send} 추가
- agent(9500) 위임 어댑터(IAgentClient) + mock(use_mock) 격리 → agent 미연동 시 1402 graceful degrade
- negotiation.chats 메시지 영속화(meta JSONB) + 종료 시 세션 입찰/거부 확정(단일 트랜잭션)
- 동시전송 가드(유저 메시지 pre-claim/CHAT_IN_PROGRESS) + 실패 시 롤백, 마감/만료 분기, init 만료 정리
- ChatSender enum, chat 에러코드(1400~1403), chats ORM 모델, AgentConfig
- 테스트 10건(test_chat.py), AGENT_INTEGRATION.md 연동 규약 문서

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
민헌andClaude Opus 4.8 committed 2026-06-18 14:24:57 +09:00
1 parent d199c1dec1
commit dcce82a630
14 files changed
+1124 -2

No files matched your search

+15
View File
@@ -44,6 +44,12 @@ class ErrorType(Enum):
NEGO_DEADLINE_PASSED = auto() # 1303 견적 마감 시간 초과
NEGO_NOT_FOUND = auto() # 1304 세션/견적 없음
# 채팅(chat) 관련 에러
CHAT_NOT_IN_PROGRESS = 1400 # 협상중 상태가 아니라 대화 불가(미참여/완료/거부)
CHAT_PRICE_OUT_OF_RANGE = auto() # 1401 제시가가 허용 범위를 벗어남
CHAT_AGENT_UNAVAILABLE = auto() # 1402 협상 에이전트(agent) 호출 실패
CHAT_IN_PROGRESS = auto() # 1403 직전 턴 처리 중(동시 전송 가드)
# ErrorType 의 HTTP_* 값과 status_code 를 맞춰 router 단에서 raise 한다.
EXCEPTION_INVALID_CLIENT_REQUEST = HTTPException(status_code=ErrorType.HTTP_INVALID_CLIENT_REQUEST.value, detail=ErrorType.HTTP_INVALID_CLIENT_REQUEST.name)
@@ -125,3 +131,12 @@ class QuotationStatus(Enum):
CREATED = 1 # 견적생성
IN_PROGRESS = 2 # 견적진행중
CLOSED = 3 # 견적마감
class ChatSender(Enum):
"""채팅 발신자 코드. negotiation.chats.sender.
BOT 은 갑(바이어/agent)이 제시하는 협상 메시지, USER 는 공급사(접속 유저)의 입력이다.
"""
BOT = 1 # 갑(바이어/agent) — bot 메시지
USER = 2 # 공급사(을) — user 입력