o2o-negosium-original/backend/router/v1/negotiation/chat_protocol.py
민헌 8f070e362b feat(chat): agent 연동 정리 — mock 제거·DB 데이터 연동·표현 passthrough
- MockAgentClient/use_mock 분기와 mock 전용 turn/count_bot_messages 제거 (항상 HttpAgentClient 위임)
- agent RL state 입력을 실 DB 로 연동: anchor_price=quotation_settings.anchoring_value 기반 계산, partner_count=견적당 세션 수 (quotation_settings 모델 추가)
- 재견적 배송형태(delivery_type) 캡처: 배송형태선택 단계 선택값을 summaryCM 요약에 반영 (DeliveryType enum 추가)
- 표현 계약 passthrough: agent 응답의 bot_chat_type/indicator_value 를 우선 사용하고 없으면 step+qt_type 으로 폴백, indicator_value 컬럼 영속/전달
- 턴당 중복 조회 제거: item/last_price 를 1회 로드해 재사용
- 관련 테스트 추가(배송형태 캡처, passthrough)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-19 17:32:50 +09:00

94 lines
3.5 KiB
Python

"""채팅(chat) 라우터 프로토콜 — backend ↔ 프론트 계약.
agent Res_Chat → 이 ChatMessage 매핑:
step→step, client_step→display_step, script→script,
input_mode→next_input_mode, input_options→next_input_type, chat_end→chat_end,
bot_chat_type→bot_chat_type, indicator_value→indicator_value.
summary(요약카드 데이터)는 backend 가 비즈니스 데이터로 조립해 채운다.
"""
from typing import Optional
from common.models.gmodel import Res_WebPacketProtocol, WebPacketProtocol
# 협상 결과 요약 카드(summaryRSP/summaryCM)에 표시할 데이터. 종료 스텝에서만 채워 내려간다.
# 필드명은 프론트 ChatSummary 타입과 1:1 (item_isVAT 등 camelCase 유지).
class ChatSummary(WebPacketProtocol):
md_name: str = ""
md_email: str = ""
md_phone_number: str = ""
item_code: str = ""
item_name: str = ""
item_spec: str = ""
item_moq: str = ""
item_model: str = ""
item_maker: str = ""
item_isVAT: bool = False
item_lead_time: str = ""
item_display_date: str = ""
item_delivery_type: str = ""
final_price: int = 0
nego_start_date: str = ""
nego_end_date: str = ""
supplier_name: str = ""
supplier_manager_name: str = ""
supplier_manager_email: str = ""
delivery_type: Optional[str] = None
# 말풍선 한 건. sender 는 ChatSender 정수 코드(1=BOT, 2=USER)로 내려가고 라벨 매핑은 프론트가 한다.
class ChatMessage(WebPacketProtocol):
chat_id: str = ""
session_id: str = ""
seq: int = 0
sender: int = 0 # ChatSender 코드
script: str = ""
user_input_type: Optional[str] = None # 유저 입력 종류: text|percent|price
step: str = ""
display_step: str = "" # agent client_step
next_input_mode: Optional[str] = None # confirm|yes_no|percent|price|delivery_type
next_input_type: Optional[list[str]] = None # 다음 입력 선택지
chat_end: bool = False
indicator_value: Optional[float] = None # 협상 지표(1~99). agent 가 가격협상 턴에 내려주면 표시.
bot_chat_type: Optional[str] = None # summaryRSP|summaryCM|rejectRSP|rejectCM|indicator
summary: Optional[ChatSummary] = None # summaryRSP/summaryCM 일 때만 채워짐
# 채팅 진입 — 상품/견적 메타 + 현재 세션 상태 + 마감 시각(타이머용)
class Res_ChatInit(Res_WebPacketProtocol):
session_id: str = ""
session_status: int = 0 # SessionStatus 코드
quotation_id: str = ""
quotation_end_time: str = "" # ISO 8601 (마감 시각)
quotation_memo: str = ""
item_id: str = ""
item_name: str = ""
item_code: str = ""
item_image: str = ""
item_price: int = 0
item_model_name: str = ""
item_maker_name: str = ""
item_spec: str = ""
item_lead_time: str = ""
item_min_order_quantity: str = ""
item_vat_yn: Optional[bool] = None
item_delivery_fee_yn: Optional[bool] = None
# 대화 히스토리(재진입 복원)
class Res_ChatMessages(Res_WebPacketProtocol):
items: list[ChatMessage] = []
# 한 턴 전송. user_input 은 버튼 텍스트 또는 가격/퍼센트 문자열.
class Req_ChatSend(WebPacketProtocol):
user_input_type: Optional[str] = None # text|percent|price
user_input: str = ""
# append-only: 새 봇 메시지 1건 + 갱신된 세션 상태만 반환(전체 refetch 회피)
class Res_ChatSend(Res_WebPacketProtocol):
message: Optional[ChatMessage] = None
session_status: int = 0