From 7bcd7a0f39c56fc5aeb883f0798d9cb1a0a789d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=AF=BC=ED=97=8C?= Date: Mon, 31 Aug 2026 15:07:57 +0900 Subject: [PATCH] =?UTF-8?q?=ED=98=91=EC=83=81=20=EC=B9=B4=EB=93=9C=20?= =?UTF-8?q?=EC=B9=B4=ED=83=88=EB=A1=9C=EA=B7=B8=20=ED=8C=9D=EC=97=85=20?= =?UTF-8?q?=E2=80=94=20=EC=84=9C=EB=B2=84=20=EC=B9=B4=EB=93=9C=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20API=20+=20=EB=B0=9C=EB=8F=99=20=EC=A4=91=20?= =?UTF-8?q?=ED=95=98=EC=9D=B4=EB=9D=BC=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - GET /v1/nego/cards: 일반 카드 9종(정본 nego_card.json) + 와일드카드 2종, 테스트 추가(15 통과) - 엔진 판단 패널 '전체 카드' 버튼 → 모달: ID·이름·스크립트, 현재 발동 카드 하이라이트, 변수 {…} 안내, 로딩·실패 상태, X/배경/ESC 닫기 Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01UFZ7JWdwCaQAwNYJErL8pP --- frontend/src/components/CardCatalog.tsx | 108 ++++++++++++++++++++++++ frontend/src/components/Dashboard.tsx | 3 +- frontend/src/lib/api.ts | 17 ++++ server/router/v1/nego/admin.py | 29 +++++++ server/tests/test_smoke.py | 10 +++ 5 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 frontend/src/components/CardCatalog.tsx diff --git a/frontend/src/components/CardCatalog.tsx b/frontend/src/components/CardCatalog.tsx new file mode 100644 index 0000000..86eda4b --- /dev/null +++ b/frontend/src/components/CardCatalog.tsx @@ -0,0 +1,108 @@ +import { useRef, useState } from 'react' +import { fetchCards, type CardCatalogResponse, type CardInfo } from '../lib/api' + +/** + * 협상 카드 카탈로그 팝업 — 엔진이 보유한 카드 전체를 정본(서버)에서 받아 보여준다. + * 현재 발동 중인 카드는 하이라이트된다. + */ +export function CardCatalog({ activeCardId }: { activeCardId: string | null }) { + const dialogRef = useRef(null) + const [data, setData] = useState(null) + const [failed, setFailed] = useState(false) + + const open = async () => { + dialogRef.current?.showModal() + if (data) return + try { + setFailed(false) + setData(await fetchCards()) + } catch { + setFailed(true) + } + } + + const CardRow = ({ card }: { card: CardInfo }) => { + const active = card.card_id === activeCardId + return ( +
  • +
    + + {card.card_id} + + {card.card_name} + {active && ( + + 발동 중 + + )} +
    +

    + {card.script} +

    +
  • + ) + } + + return ( + <> + + + +
    +
    +
    +

    협상 카드 목록

    +

    + 엔진이 상황에 맞춰 꺼내 쓰는 카드입니다. {'{...}'} 부분은 협상 시점의 실제 값으로 채워집니다. +

    +
    +
    + +
    +
    + +
    + {failed ? ( +

    + 카드 목록을 불러오지 못했어요. 엔진 연결을 확인한 뒤 다시 열어 주세요. +

    + ) : !data ? ( +

    + + 카드 목록을 불러오고 있어요 +

    + ) : ( + <> +

    + 일반 협상 카드 {data.cards.length}종 +

    +
      + {data.cards.map((c) => )} +
    +

    + 와일드카드 {data.wild_cards.length}종 — 마지막 라운드 승부수 +

    +
      + {data.wild_cards.map((c) => )} +
    + + )} +
    +
    +
    + +
    +
    + + ) +} diff --git a/frontend/src/components/Dashboard.tsx b/frontend/src/components/Dashboard.tsx index 364cda3..e13be56 100644 --- a/frontend/src/components/Dashboard.tsx +++ b/frontend/src/components/Dashboard.tsx @@ -1,6 +1,7 @@ import type { ChatMetadata } from '../lib/api' import type { DemoCase } from '../content/cases' import type { NegoState, Round } from '../App' +import { CardCatalog } from './CardCatalog' const FLOW = ['서비스안내', '담당자확인', '협상품목안내', '가격협상', '협상종료'] const MAX_ROUNDS = 6 // 시작 제안 1회 + 재협상 5회(엔진 MAX_ITERATION) @@ -113,7 +114,7 @@ export function Dashboard({ )} - + }> {meta ? (
    {/* 이 패널의 주인공 — 지금 발동 중인 협상 카드 */} diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index c4b7592..d00349a 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -63,6 +63,23 @@ export async function invalidateSession(sessionId: string): Promise { }) } +export interface CardInfo { + card_id: string + card_name: string + script: string +} + +export interface CardCatalogResponse { + cards: CardInfo[] + wild_cards: CardInfo[] +} + +export async function fetchCards(): Promise { + const res = await fetch('/api/v1/nego/cards') + if (!res.ok) throw new Error(`서버 응답 오류 (${res.status})`) + return res.json() +} + export async function serverAlive(): Promise { try { const res = await fetch('/api/health') diff --git a/server/router/v1/nego/admin.py b/server/router/v1/nego/admin.py index 31bd2dd..5e96e2b 100644 --- a/server/router/v1/nego/admin.py +++ b/server/router/v1/nego/admin.py @@ -1,11 +1,20 @@ """상태 확인 엔드포인트.""" +import json + from fastapi import APIRouter, Request +from common.paths import RESOURCES_DIR from router.v1.nego.protocol import HealthResponse router = APIRouter(tags=["admin"]) +# 와일드카드는 스텝 ID로 관리되므로 표시용 이름을 여기서 부여한다 +WILD_CARD_LABELS = { + "wild_card_1pct": "1% 추가 제안", + "wild_card_budget": "재원부족 제안", +} + @router.get("/health", response_model=HealthResponse) async def health_check(): @@ -31,3 +40,23 @@ async def get_config(request: Request): }, "cards": engine.card_script_repo.count(), } + + +@router.get("/v1/nego/cards") +async def list_cards(request: Request): + """협상 카드 전체 목록 — 데모 콘솔의 카드 팝업용 (정본 = resources/cards).""" + engine = request.app.state.engine + cards = [ + {"card_id": c.get("card_id"), "card_name": c.get("card_name"), "script": c.get("script", "")} + for c in engine.card_script_repo.find_all() + ] + wild_cards = [] + try: + wild = json.loads((RESOURCES_DIR / "cards" / "wild_card.json").read_text(encoding="utf-8")) + wild_cards = [ + {"card_id": key, "card_name": WILD_CARD_LABELS.get(key, key), "script": item.get("script", "")} + for key, item in wild.items() + ] + except (OSError, json.JSONDecodeError): + pass + return {"cards": cards, "wild_cards": wild_cards} diff --git a/server/tests/test_smoke.py b/server/tests/test_smoke.py index d66d964..d424e4e 100644 --- a/server/tests/test_smoke.py +++ b/server/tests/test_smoke.py @@ -119,3 +119,13 @@ def test_session_invalidate(): json={"session_id": "TEST-01", "reason": "테스트"}) assert res.status_code == 200 assert res.json()["status"] == "ok" + + +def test_cards_endpoint(): + """카드 목록 — 데모 카드 팝업용. 일반 9종 + 와일드 2종, 이름 필수.""" + res = client.get("/v1/nego/cards") + assert res.status_code == 200 + body = res.json() + assert len(body["cards"]) == 9 + assert all(c["card_id"] and c["card_name"] and c["script"] for c in body["cards"]) + assert {w["card_id"] for w in body["wild_cards"]} == {"wild_card_1pct", "wild_card_budget"}