초기 커밋 — 협상 AI 에이전트 정본: 엔진·데모 콘솔·측정 인프라·증빙

- server/: FastAPI 협상 엔진 (5라운드, Q-Table/UCB, 페르소나 계측, :53117)
- frontend/: 데모 콘솔 (React+Tailwind → nginx, /api 프록시)
- eval/·testdata/: 지표 8종 측정 하네스 + 재현 가능 테스트셋
- results/: 측정 증빙 (지표별 result+provenance, raw 원본 동결+SHA256)
  ① 86.0 · ② 76.0 · ③ 5.99% · ⑥ p95 3.61ms · ⑦ 611만/년 · ⑧ 91/100 · ⑨ 99.71 · ⑩ 97.99
- docker-compose.yml + run.sh: backend+frontend 일괄 기동

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0112XUWF4bc3gGrEt8vsYCzy
This commit is contained in:
민헌andClaude Fable 5 committed 2026-08-31 13:09:52 +09:00
commit dfb9ad6e66
268 files changed
+164241

No files matched your search

+184
View File
@@ -0,0 +1,184 @@
import { useEffect, useRef, useState } from 'react'
import type { ChatMetadata } from '../lib/api'
import type { DemoCase } from '../content/cases'
import type { NegoState } from '../App'
export interface Msg {
role: 'bot' | 'user'
text: string
step?: string
meta?: ChatMetadata | null
}
// 내부 스텝 ID → 관람자용 라벨 (엔진 내부명 노출 방지)
const STEP_LABELS: Record<string, string> = {
wild_card_1pct: '1% 추가 제안',
wild_card_budget: '재원부족 제안',
가격협상_확인_버짓: '가격협상 확인',
}
const stepLabel = (s: string) => STEP_LABELS[s] ?? s
export function ChatPanel({
messages, nego, busy, started, error, demoCase, finalPrice, onAnswer, onOffer, onRestart,
}: {
messages: Msg[]
nego: NegoState
busy: boolean
started: boolean
error: string | null
demoCase: DemoCase
finalPrice: number | null
onAnswer: (label: string) => void
onOffer: (v: number) => void
onRestart: () => void
}) {
const [priceInput, setPriceInput] = useState('')
const scroller = useRef<HTMLDivElement>(null)
useEffect(() => {
scroller.current?.scrollTo({ top: scroller.current.scrollHeight, behavior: 'smooth' })
}, [messages, busy])
useEffect(() => setPriceInput(''), [nego.step])
const submitPrice = () => {
const v = Number(priceInput.replaceAll(',', ''))
if (!Number.isFinite(v) || v <= 0) return
onOffer(Math.round(v))
}
const savedPct = finalPrice != null
? Math.round(((demoCase.item_price - finalPrice) / demoCase.item_price) * 1000) / 10
: null
return (
<section className="flex min-h-[70vh] flex-col rounded-xl border border-line bg-panel min-[960px]:h-full min-[960px]:min-h-0">
{started && (
<div className="flex items-center justify-between gap-3 border-b border-line px-4 py-2.5">
<span className="truncate text-sm font-semibold">{demoCase.item_name}</span>
{!nego.done && (
<button
type="button"
onClick={onRestart}
disabled={busy}
className="shrink-0 rounded-md border border-line px-2.5 py-1 text-xs text-muted hover:border-muted hover:text-ink disabled:opacity-40 focus-visible:ring-2 focus-visible:ring-blue focus-visible:outline-none"
>
다시 시작
</button>
)}
</div>
)}
<div ref={scroller} className="flex-1 overflow-y-auto p-4">
{!started && (
<div className="flex h-full flex-col items-center justify-center gap-2 text-center text-muted">
<p className="text-base font-medium text-ink">협상 준비 완료</p>
<p className="max-w-sm text-sm leading-relaxed">
왼쪽에서 협상 케이스를 선택하세요. 협상 카드·가격 지표·긴장도가
오른쪽 계기판에 실시간으로 표시됩니다.
</p>
</div>
)}
<ol className="flex flex-col gap-3">
{messages.map((m, i) => (
<li key={i} className={`msg-in flex ${m.role === 'user' ? 'justify-end' : 'justify-start'}`}>
<div
className={`max-w-[min(82%,34rem)] rounded-2xl px-4 py-3 text-[15px] leading-relaxed whitespace-pre-line ${
m.role === 'user'
? 'rounded-br-md bg-blue text-white'
: 'rounded-bl-md bg-bot'
}`}
>
{m.role === 'bot' && m.step && (
<div className="mb-1 flex items-center gap-2 text-[11px] font-semibold text-muted">
<span>{stepLabel(m.step)}</span>
{m.meta?.card_id && (
<span className="rounded bg-blue-soft px-1.5 py-px font-mono text-blue">{m.meta.card_id}</span>
)}
</div>
)}
{m.text}
</div>
</li>
))}
{busy && (
<li className="flex justify-start">
<div className="rounded-2xl rounded-bl-md bg-bot px-4 py-3 text-sm text-muted">협상 중…</div>
</li>
)}
</ol>
{error && (
<p className="mt-3 rounded-lg bg-amber-soft px-3 py-2 text-sm text-amber">
{error} — 서버(:53117)가 켜져 있는지 확인한 뒤 다시 시도하세요.
</p>
)}
</div>
<div className="border-t border-line p-3">
{nego.done ? (
<div className="flex flex-wrap items-center justify-between gap-3">
{finalPrice != null ? (
<span className="text-sm">
<span className="font-semibold text-green">협상 완료</span>
<span className="text-muted"> — 최종 합의가 </span>
<span className="font-mono font-semibold">{finalPrice.toLocaleString()}원</span>
<span className="font-mono text-blue"> (기존가 대비 −{savedPct}%)</span>
</span>
) : (
<span className="text-sm font-semibold">협상이 종료되었습니다</span>
)}
<button
type="button"
onClick={onRestart}
className="rounded-lg bg-ink px-4 py-2 text-sm font-semibold text-white hover:bg-ink/85 focus-visible:ring-2 focus-visible:ring-blue focus-visible:outline-none"
>
같은 케이스로 다시 협상
</button>
</div>
) : nego.mode === 'price' ? (
<form
className="flex gap-2"
onSubmit={(e) => { e.preventDefault(); submitPrice() }}
>
<label htmlFor="price" className="sr-only">공급 제안가 (원)</label>
<input
id="price"
inputMode="numeric"
autoComplete="off"
placeholder={`공급 제안가 입력 (기존가 ${demoCase.item_price.toLocaleString()}원)`}
value={priceInput}
onChange={(e) => setPriceInput(e.target.value)}
disabled={busy}
className="min-w-0 flex-1 rounded-lg border border-line bg-paper px-3 py-2.5 font-mono text-sm focus-visible:ring-2 focus-visible:ring-blue focus-visible:outline-none"
/>
<button
type="submit"
disabled={busy || !priceInput.trim()}
className="shrink-0 rounded-lg bg-blue px-5 py-2.5 text-sm font-semibold text-white disabled:opacity-40 hover:bg-blue/90 focus-visible:ring-2 focus-visible:ring-ink focus-visible:outline-none"
>
제안
</button>
</form>
) : nego.options.length > 0 ? (
<div className="flex flex-wrap gap-2">
{nego.options.map((opt) => (
<button
key={opt}
type="button"
disabled={busy}
onClick={() => onAnswer(opt)}
className="rounded-lg border border-line bg-paper px-4 py-2.5 text-sm font-medium hover:border-blue hover:text-blue disabled:opacity-40 focus-visible:ring-2 focus-visible:ring-blue focus-visible:outline-none"
>
{opt}
</button>
))}
</div>
) : (
<p className="py-1 text-center text-sm text-muted">
{started ? '응답을 기다리는 중…' : '케이스를 선택하면 입력이 열립니다'}
</p>
)}
</div>
</section>
)
}