초기 커밋 — 협상 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:
commit
dfb9ad6e66
268 files changed
+164241
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import { DIST_LABEL, type DemoCase } from '../content/cases'
|
||||
|
||||
export function CasePanel({
|
||||
cases, selected, started, busy, onStart,
|
||||
}: {
|
||||
cases: DemoCase[]
|
||||
selected: DemoCase
|
||||
started: boolean
|
||||
busy: boolean
|
||||
onStart: (c: DemoCase) => void
|
||||
}) {
|
||||
return (
|
||||
<aside className="flex flex-col gap-3 min-[960px]:min-h-0 min-[960px]:overflow-y-auto">
|
||||
<section className="rounded-xl border border-line bg-panel p-4">
|
||||
<h2 className="text-xs font-semibold uppercase tracking-wider text-muted">협상 케이스</h2>
|
||||
<ul className="mt-3 flex flex-col gap-2">
|
||||
{cases.map((c) => {
|
||||
const active = started && c.id === selected.id
|
||||
return (
|
||||
<li key={c.id}>
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy}
|
||||
onClick={() => onStart(c)}
|
||||
className={`w-full rounded-lg border px-3 py-2.5 text-left transition-colors focus-visible:ring-2 focus-visible:ring-blue focus-visible:outline-none ${
|
||||
active
|
||||
? 'border-blue bg-blue-soft'
|
||||
: 'border-line bg-panel hover:border-muted'
|
||||
} ${busy ? 'opacity-60' : ''}`}
|
||||
>
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<span className="text-sm font-semibold">{c.item_name}</span>
|
||||
<span className="shrink-0 rounded bg-paper px-1.5 py-0.5 text-[11px] text-muted">{c.label}</span>
|
||||
</div>
|
||||
<div className="mt-1 font-mono text-xs text-muted">
|
||||
기존 공급가 {c.item_price.toLocaleString()}원
|
||||
</div>
|
||||
{active && (
|
||||
<dl className="mt-2 grid grid-cols-2 gap-x-2 gap-y-1 border-t border-line pt-2 text-[11px]">
|
||||
<dt className="text-muted">공급 유형</dt>
|
||||
<dd className="text-right">{DIST_LABEL[c.dist]} · {c.partners_yn}</dd>
|
||||
<dt className="text-muted">거래 기간</dt>
|
||||
<dd className="text-right font-mono">{c.card_data.trading_period}년</dd>
|
||||
<dt className="text-muted">응답률 / VOC</dt>
|
||||
<dd className="text-right font-mono">{c.card_data.response_rate}% / {c.card_data.voc_count}건</dd>
|
||||
</dl>
|
||||
)}
|
||||
</button>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
{!started && (
|
||||
<p className="mt-3 text-xs leading-relaxed text-muted">
|
||||
케이스를 선택하면 협상이 시작됩니다. 챗봇은 구매 담당자(MD) 역할이고,
|
||||
당신은 공급사로서 가격 제안에 응답합니다.
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
</aside>
|
||||
)
|
||||
}
|
||||
@@ -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>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
import type { ChatMetadata } from '../lib/api'
|
||||
import type { DemoCase } from '../content/cases'
|
||||
import type { NegoState } from '../App'
|
||||
import { PriceTrack } from './PriceTrack'
|
||||
|
||||
const FLOW = ['서비스안내', '담당자확인', '협상품목안내', '가격협상', '협상종료']
|
||||
|
||||
function flowIndex(step: string): number {
|
||||
if (step.includes('종료') || step.includes('완료') || step.includes('실패')) return 4
|
||||
if (step.includes('가격') || step.startsWith('wild_')) return 3
|
||||
const i = FLOW.indexOf(step)
|
||||
return i >= 0 ? i : 0
|
||||
}
|
||||
|
||||
function Panel({ title, children }: { title: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<section className="rounded-xl border border-line bg-panel p-4">
|
||||
<h2 className="text-xs font-semibold uppercase tracking-wider text-muted">{title}</h2>
|
||||
<div className="mt-3">{children}</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export function Dashboard({
|
||||
demoCase, nego, meta, priceTrail, started,
|
||||
}: {
|
||||
demoCase: DemoCase
|
||||
nego: NegoState
|
||||
meta: ChatMetadata | null
|
||||
priceTrail: number[]
|
||||
started: boolean
|
||||
}) {
|
||||
const fi = started ? flowIndex(nego.step) : -1
|
||||
const tension = meta?.tension ?? null
|
||||
const indicator = meta?.indicator_value ?? null
|
||||
|
||||
return (
|
||||
<aside className="flex flex-col gap-3 min-[960px]:min-h-0 min-[960px]:overflow-y-auto">
|
||||
<Panel title="가격 트랙">
|
||||
<PriceTrack demoCase={demoCase} priceTrail={priceTrail} />
|
||||
<dl className="mt-3 flex items-center justify-between border-t border-line pt-2.5 text-xs">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<dt className="text-muted">시나리오</dt>
|
||||
<dd className="font-mono font-medium">{demoCase.scenario.replace('Scenario_', '')}</dd>
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<dt className="text-muted">인터넷 최저가</dt>
|
||||
<dd className="font-mono font-medium">{demoCase.card_data.internet_min_price.toLocaleString()}원</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<p className="mt-2 text-[11px] leading-relaxed text-muted">
|
||||
앵커가·목표가는 실제 협상에서 공급사에게 보이지 않는 구매측 내부 기준입니다.
|
||||
</p>
|
||||
</Panel>
|
||||
|
||||
<Panel title="협상 진행">
|
||||
<ol className="flex items-center gap-1">
|
||||
{FLOW.map((s, i) => (
|
||||
<li key={s} className="flex flex-1 flex-col items-center gap-1.5">
|
||||
<div
|
||||
className={`h-1.5 w-full rounded-full ${
|
||||
i < fi ? 'bg-blue/40' : i === fi ? 'bg-blue' : 'bg-line'
|
||||
}`}
|
||||
/>
|
||||
<span className={`text-[10px] ${i === fi ? 'font-semibold text-ink' : 'text-muted'}`}>{s}</span>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
<div className="mt-3 flex items-center justify-between text-sm">
|
||||
<span className="text-muted">가격 라운드</span>
|
||||
<span className="font-mono font-medium">{Math.min(nego.iteration + (nego.initial ? 1 : 0), 5)} / 5</span>
|
||||
</div>
|
||||
</Panel>
|
||||
|
||||
<Panel title="엔진 판단">
|
||||
{meta ? (
|
||||
<dl className="flex flex-col gap-3 text-sm">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<dt className="text-muted">협상 카드</dt>
|
||||
<dd className="rounded bg-blue-soft px-2 py-0.5 font-mono text-[13px] font-medium text-blue">
|
||||
{meta.card_id ?? '—'}
|
||||
</dd>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className="flex items-center justify-between">
|
||||
<dt className="text-muted">가격 지표</dt>
|
||||
<dd className="font-mono text-[13px]">
|
||||
{indicator != null ? (
|
||||
<>
|
||||
{indicator} <span className="text-muted">/ 99 · {meta.indicator_range}</span>
|
||||
</>
|
||||
) : '—'}
|
||||
</dd>
|
||||
</div>
|
||||
<div className="mt-1.5 h-1.5 rounded-full bg-paper">
|
||||
<div
|
||||
className="h-full rounded-full bg-blue transition-[width] duration-500"
|
||||
style={{ width: `${indicator ?? 0}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className="flex items-center justify-between">
|
||||
<dt className="text-muted">협상 긴장도</dt>
|
||||
<dd className="font-mono text-[13px]">{tension != null ? tension.toFixed(2) : '—'}</dd>
|
||||
</div>
|
||||
<div className="mt-1.5 h-1.5 rounded-full bg-paper">
|
||||
<div
|
||||
className="h-full rounded-full bg-amber transition-[width] duration-500"
|
||||
style={{ width: `${(tension ?? 0) * 100}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<dt className="text-muted">적용 페르소나</dt>
|
||||
<dd>
|
||||
{meta.persona ? (
|
||||
<span className="rounded bg-amber-soft px-2 py-0.5 text-[13px] font-medium text-amber">
|
||||
{meta.persona}
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-muted">—</span>
|
||||
)}
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
) : (
|
||||
<p className="text-xs leading-relaxed text-muted">
|
||||
{nego.done
|
||||
? '카드 라운드 없이 조기 합의됐습니다 — 첫 제안가가 앵커가 이하면 협상 카드 없이 종료됩니다.'
|
||||
: '가격 협상이 시작되면 선택된 협상 카드와 가격 지표·긴장도·페르소나가 여기에 표시됩니다.'}
|
||||
</p>
|
||||
)}
|
||||
</Panel>
|
||||
</aside>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import type { DemoCase } from '../content/cases'
|
||||
|
||||
/**
|
||||
* 가격 트랙 — 이 페이지의 시그니처.
|
||||
* 앵커가·목표가·기존 공급가를 한 수평 트랙에 놓고, 제안가가 내려오는 과정을 마커로 보여준다.
|
||||
* 파랑 구간(앵커 이하) = 구매측 최적 · 앰버 구간(목표가 초과) = 협상 여지.
|
||||
*/
|
||||
export function PriceTrack({ demoCase, priceTrail }: { demoCase: DemoCase; priceTrail: number[] }) {
|
||||
const { anchor, target, item_price } = demoCase
|
||||
const current = priceTrail.length ? priceTrail[priceTrail.length - 1] : null
|
||||
|
||||
// 트랙 범위: min(앵커, 최저 제안가) 아래 여유 3% ~ max(기존가, 최고 제안가) 위 여유 3%
|
||||
// (제안가가 앵커보다 낮아도 마커가 트랙 밖으로 클리핑되지 않도록 동적 확장)
|
||||
const hi = Math.max(item_price, ...(priceTrail.length ? priceTrail : [item_price])) * 1.03
|
||||
const lo = Math.min(anchor, ...(priceTrail.length ? priceTrail : [anchor])) * 0.97
|
||||
const pos = (v: number) => Math.min(Math.max(((v - lo) / (hi - lo)) * 100, 0), 100)
|
||||
|
||||
const Tick = ({ value, label, cls }: { value: number; label: string; cls: string }) => (
|
||||
<div className="absolute top-0 h-full" style={{ left: `${pos(value)}%` }}>
|
||||
<div className={`h-full w-px ${cls}`} />
|
||||
<div className="absolute top-full mt-1 -translate-x-1/2 text-center">
|
||||
<div className="text-[10px] leading-tight text-muted">{label}</div>
|
||||
<div className="font-mono text-[11px] font-medium leading-tight">{value.toLocaleString()}</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="relative mb-9 mt-6 h-3 rounded-full bg-paper">
|
||||
{/* 구간 채색: [lo~anchor]=파랑(최적) · [anchor~target]=연파랑(합의권) · [target~hi]=앰버(초과) */}
|
||||
<div className="absolute inset-y-0 left-0 rounded-l-full bg-blue/70" style={{ width: `${pos(anchor)}%` }} />
|
||||
<div
|
||||
className="absolute inset-y-0 bg-blue-soft"
|
||||
style={{ left: `${pos(anchor)}%`, width: `${pos(target) - pos(anchor)}%` }}
|
||||
/>
|
||||
<div
|
||||
className="absolute inset-y-0 rounded-r-full bg-amber-soft"
|
||||
style={{ left: `${pos(target)}%`, width: `${100 - pos(target)}%` }}
|
||||
/>
|
||||
<Tick value={anchor} label="앵커가" cls="bg-blue" />
|
||||
<Tick value={target} label="목표가" cls="bg-ink/50" />
|
||||
<Tick value={item_price} label="기존가" cls="bg-muted/60" />
|
||||
|
||||
{/* 과거 제안 흔적 */}
|
||||
{priceTrail.slice(0, -1).map((p, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="absolute top-1/2 size-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-ink/25"
|
||||
style={{ left: `${pos(p)}%` }}
|
||||
/>
|
||||
))}
|
||||
|
||||
{/* 현재 제안가 마커 */}
|
||||
{current != null && (
|
||||
<div
|
||||
className="track-marker absolute top-1/2 -translate-x-1/2 -translate-y-1/2"
|
||||
style={{ left: `${pos(current)}%` }}
|
||||
>
|
||||
<div className="size-4 rounded-full border-[3px] border-ink bg-white shadow-sm" />
|
||||
<div className="absolute bottom-full left-1/2 mb-1.5 -translate-x-1/2 whitespace-nowrap rounded bg-ink px-1.5 py-0.5 font-mono text-[11px] font-semibold text-white">
|
||||
{current.toLocaleString()}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{current == null && (
|
||||
<p className="text-xs text-muted">첫 제안가를 입력하면 트랙 위에 표시됩니다.</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user