초기 커밋 — 협상 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,155 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { DEMO_CASES, type DemoCase } from './content/cases'
|
||||
import { buildCardData, chat, invalidateSession, serverAlive, type ChatMetadata } from './lib/api'
|
||||
import { CasePanel } from './components/CasePanel'
|
||||
import { ChatPanel, type Msg } from './components/ChatPanel'
|
||||
import { Dashboard } from './components/Dashboard'
|
||||
|
||||
export interface NegoState {
|
||||
step: string
|
||||
index: number
|
||||
iteration: number
|
||||
price: number | null
|
||||
initial: number | null
|
||||
mode: string
|
||||
options: string[]
|
||||
done: boolean
|
||||
}
|
||||
|
||||
const IDLE: NegoState = {
|
||||
step: '시작', index: 0, iteration: 0, price: null, initial: null,
|
||||
mode: 'null', options: [], done: false,
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const [demoCase, setDemoCase] = useState<DemoCase>(DEMO_CASES[0])
|
||||
const [nego, setNego] = useState<NegoState>(IDLE)
|
||||
const [messages, setMessages] = useState<Msg[]>([])
|
||||
const [meta, setMeta] = useState<ChatMetadata | null>(null)
|
||||
const [finalPrice, setFinalPrice] = useState<number | null>(null)
|
||||
const [priceTrail, setPriceTrail] = useState<number[]>([])
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [started, setStarted] = useState(false)
|
||||
const [runId, setRunId] = useState(0)
|
||||
const [alive, setAlive] = useState<boolean | null>(null)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const session = useRef(`DEMO-${Date.now()}`)
|
||||
|
||||
useEffect(() => {
|
||||
serverAlive().then(setAlive)
|
||||
const t = setInterval(() => serverAlive().then(setAlive), 15000)
|
||||
return () => clearInterval(t)
|
||||
}, [])
|
||||
|
||||
const send = useCallback(
|
||||
async (userInput: string | null, state: NegoState, userLabel?: string) => {
|
||||
setBusy(true)
|
||||
setError(null)
|
||||
if (userLabel) setMessages((m) => [...m, { role: 'user', text: userLabel }])
|
||||
try {
|
||||
const res = await chat({
|
||||
rq_type: '재협상',
|
||||
session_id: session.current,
|
||||
step: state.step,
|
||||
index: state.index,
|
||||
user_input: userInput,
|
||||
item_price: demoCase.item_price,
|
||||
revenue: demoCase.revenue,
|
||||
dist: demoCase.dist,
|
||||
partners_yn: demoCase.partners_yn,
|
||||
partners: demoCase.partners,
|
||||
anchor: demoCase.anchor,
|
||||
target: demoCase.target,
|
||||
initial: state.initial,
|
||||
input: state.price,
|
||||
iteration: state.iteration,
|
||||
is_new_quote: false, // UCB 에피소드 활성 — 라운드마다 다른 카드 (시연 다양성)
|
||||
profiling: false,
|
||||
card_data: buildCardData(demoCase, state.price),
|
||||
})
|
||||
setMessages((m) => [...m, { role: 'bot', text: res.script, step: res.step, meta: res.chat_metadata }])
|
||||
if (res.chat_metadata?.card_id || res.chat_metadata?.tension != null) setMeta(res.chat_metadata)
|
||||
if (res.step === '협상완료' && res.chat_metadata?.price != null) setFinalPrice(res.chat_metadata.price)
|
||||
setNego({
|
||||
...state,
|
||||
step: res.step,
|
||||
index: res.index,
|
||||
mode: res.chat_end ? 'null' : res.next_input_mode,
|
||||
options: res.input_options ?? [],
|
||||
done: res.chat_end,
|
||||
})
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : '요청 실패')
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
},
|
||||
[demoCase],
|
||||
)
|
||||
|
||||
const start = useCallback(async (c: DemoCase) => {
|
||||
session.current = `DEMO-${Date.now()}`
|
||||
await invalidateSession(session.current).catch(() => {})
|
||||
setDemoCase(c)
|
||||
setMessages([])
|
||||
setMeta(null)
|
||||
setFinalPrice(null)
|
||||
setPriceTrail([])
|
||||
setStarted(true)
|
||||
setNego(IDLE)
|
||||
setRunId((r) => r + 1)
|
||||
}, [])
|
||||
|
||||
// 케이스 확정 후 첫 요청 (같은 케이스 재시작 포함 — runId로 항상 발사)
|
||||
useEffect(() => {
|
||||
if (started) send(null, IDLE)
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [runId])
|
||||
|
||||
const answer = (label: string) => send(label, nego, label)
|
||||
|
||||
const offer = (v: number) => {
|
||||
const next = { ...nego, price: v }
|
||||
if (next.initial == null) next.initial = v
|
||||
else next.iteration = nego.iteration + 1
|
||||
setPriceTrail((t) => [...t, v])
|
||||
send(null, next, `${v.toLocaleString()}원 제안`)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex min-h-dvh flex-col min-[960px]:h-dvh">
|
||||
<header className="flex items-center justify-between border-b border-line bg-panel px-6 py-3">
|
||||
<div className="flex items-baseline gap-3">
|
||||
<h1 className="text-lg font-extrabold tracking-tight">NEGO 협상 콘솔</h1>
|
||||
<span className="text-sm text-muted">구매 협상 에이전트 시연 — 당신은 공급사입니다</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<span
|
||||
className={`inline-block size-2 rounded-full ${
|
||||
alive == null ? 'bg-line' : alive ? 'bg-green' : 'bg-amber'
|
||||
}`}
|
||||
aria-hidden
|
||||
/>
|
||||
<span className="text-muted">{alive == null ? '확인 중' : alive ? '엔진 연결됨' : '엔진 응답 없음 (:53117)'}</span>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main className="mx-auto grid w-full max-w-screen-2xl flex-1 grid-cols-1 gap-4 p-4 min-[960px]:min-h-0 min-[960px]:grid-cols-[250px_minmax(0,1fr)_320px]">
|
||||
<CasePanel cases={DEMO_CASES} selected={demoCase} started={started} busy={busy} onStart={start} />
|
||||
<ChatPanel
|
||||
messages={messages}
|
||||
nego={nego}
|
||||
busy={busy}
|
||||
started={started}
|
||||
error={error}
|
||||
demoCase={demoCase}
|
||||
finalPrice={finalPrice}
|
||||
onAnswer={answer}
|
||||
onOffer={offer}
|
||||
onRestart={() => start(demoCase)}
|
||||
/>
|
||||
<Dashboard demoCase={demoCase} nego={nego} meta={meta} priceTrail={priceTrail} started={started} />
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="77" height="47" fill="none" aria-labelledby="vite-logo-title" viewBox="0 0 77 47"><title id="vite-logo-title">Vite</title><style>.parenthesis{fill:#000}@media (prefers-color-scheme:dark){.parenthesis{fill:#fff}}</style><path fill="#9135ff" d="M40.151 45.71c-.663.844-2.02.374-2.02-.699V34.708a2.26 2.26 0 0 0-2.262-2.262H24.493c-.92 0-1.457-1.04-.92-1.788l7.479-10.471c1.07-1.498 0-3.578-1.842-3.578H15.443c-.92 0-1.456-1.04-.92-1.788l9.696-13.576c.213-.297.556-.474.92-.474h28.894c.92 0 1.456 1.04.92 1.788l-7.48 10.472c-1.07 1.497 0 3.578 1.842 3.578h11.376c.944 0 1.474 1.087.89 1.83L40.153 45.712z"/><mask id="a" width="48" height="47" x="14" y="0" maskUnits="userSpaceOnUse" style="mask-type:alpha"><path fill="#000" d="M40.047 45.71c-.663.843-2.02.374-2.02-.699V34.708a2.26 2.26 0 0 0-2.262-2.262H24.389c-.92 0-1.457-1.04-.92-1.788l7.479-10.472c1.07-1.497 0-3.578-1.842-3.578H15.34c-.92 0-1.456-1.04-.92-1.788l9.696-13.575c.213-.297.556-.474.92-.474H53.93c.92 0 1.456 1.04.92 1.788L47.37 13.03c-1.07 1.498 0 3.578 1.842 3.578h11.376c.944 0 1.474 1.088.89 1.831L40.049 45.712z"/></mask><g mask="url(#a)"><g filter="url(#b)"><ellipse cx="5.508" cy="14.704" fill="#eee6ff" rx="5.508" ry="14.704" transform="rotate(269.814 20.96 11.29)scale(-1 1)"/></g><g filter="url(#c)"><ellipse cx="10.399" cy="29.851" fill="#eee6ff" rx="10.399" ry="29.851" transform="rotate(89.814 -16.902 -8.275)scale(1 -1)"/></g><g filter="url(#d)"><ellipse cx="5.508" cy="30.487" fill="#8900ff" rx="5.508" ry="30.487" transform="rotate(89.814 -19.197 -7.127)scale(1 -1)"/></g><g filter="url(#e)"><ellipse cx="5.508" cy="30.599" fill="#8900ff" rx="5.508" ry="30.599" transform="rotate(89.814 -25.928 4.177)scale(1 -1)"/></g><g filter="url(#f)"><ellipse cx="5.508" cy="30.599" fill="#8900ff" rx="5.508" ry="30.599" transform="rotate(89.814 -25.738 5.52)scale(1 -1)"/></g><g filter="url(#g)"><ellipse cx="14.072" cy="22.078" fill="#eee6ff" rx="14.072" ry="22.078" transform="rotate(93.35 31.245 55.578)scale(-1 1)"/></g><g filter="url(#h)"><ellipse cx="3.47" cy="21.501" fill="#8900ff" rx="3.47" ry="21.501" transform="rotate(89.009 35.419 55.202)scale(-1 1)"/></g><g filter="url(#i)"><ellipse cx="3.47" cy="21.501" fill="#8900ff" rx="3.47" ry="21.501" transform="rotate(89.009 35.419 55.202)scale(-1 1)"/></g><g filter="url(#j)"><ellipse cx="14.592" cy="9.743" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(39.51 14.592 9.743)"/></g><g filter="url(#k)"><ellipse cx="61.728" cy="-5.321" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(37.892 61.728 -5.32)"/></g><g filter="url(#l)"><ellipse cx="55.618" cy="7.104" fill="#00c2ff" rx="5.971" ry="9.665" transform="rotate(37.892 55.618 7.104)"/></g><g filter="url(#m)"><ellipse cx="12.326" cy="39.103" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(37.892 12.326 39.103)"/></g><g filter="url(#n)"><ellipse cx="12.326" cy="39.103" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(37.892 12.326 39.103)"/></g><g filter="url(#o)"><ellipse cx="49.857" cy="30.678" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(37.892 49.857 30.678)"/></g><g filter="url(#p)"><ellipse cx="52.623" cy="33.171" fill="#00c2ff" rx="5.971" ry="15.297" transform="rotate(37.892 52.623 33.17)"/></g></g><path d="M6.919 0c-9.198 13.166-9.252 33.575 0 46.789h6.215c-9.25-13.214-9.196-33.623 0-46.789zm62.424 0h-6.215c9.198 13.166 9.252 33.575 0 46.789h6.215c9.25-13.214 9.196-33.623 0-46.789" class="parenthesis"/><defs><filter id="b" width="60.045" height="41.654" x="-5.564" y="16.92" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="7.659"/></filter><filter id="c" width="90.34" height="51.437" x="-40.407" y="-6.762" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="7.659"/></filter><filter id="d" width="79.355" height="29.4" x="-35.435" y="2.801" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="e" width="79.579" height="29.4" x="-30.84" y="20.8" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="f" width="79.579" height="29.4" x="-29.307" y="21.949" color-interpolation-filters="sRGB" filterUnits="usLine truncated
|
||||
|
After Width: | Height: | Size: 8.5 KiB |
@@ -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>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
// 시연용 프리셋 케이스 — testdata/testset_1000.json에서 공급 유형별로 발췌.
|
||||
// 사용자는 공급사 역할, 서버(MD 챗봇)는 구매측이다.
|
||||
|
||||
export interface CardData {
|
||||
internet_min_price: number
|
||||
anchoring_price: number
|
||||
competitor_price_diff: number
|
||||
trading_period: number
|
||||
cumulative_amount: number
|
||||
supplier_ranking: number
|
||||
item_amount: number
|
||||
item_ratio: number
|
||||
voc_count: number
|
||||
response_rate: number
|
||||
product_sales_period: string
|
||||
payment_terms: string
|
||||
alternative_supplier_count: number
|
||||
}
|
||||
|
||||
export interface DemoCase {
|
||||
id: string
|
||||
label: string // 공급 유형 설명
|
||||
item_name: string
|
||||
item_price: number // 기존 공급가
|
||||
revenue: number
|
||||
dist: 'R' | 'W' | 'M'
|
||||
partners_yn: '다수' | '단독' | '없음'
|
||||
partners: number
|
||||
anchor: number // 앵커가 (구매측 내부 — 계기판에만 표시)
|
||||
target: number // 목표가 (구매측 내부 — 계기판에만 표시)
|
||||
scenario: string
|
||||
card_data: CardData
|
||||
}
|
||||
|
||||
export const DEMO_CASES: DemoCase[] = [
|
||||
{
|
||||
id: 'preset-1',
|
||||
label: '유통 (Type A)',
|
||||
item_name: 'NAS용 HDD 8T',
|
||||
item_price: 20920, revenue: 26968712,
|
||||
dist: 'R', partners_yn: '없음', partners: 0,
|
||||
anchor: 19366, target: 20173, scenario: 'Scenario_B',
|
||||
card_data: { internet_min_price: 20865, anchoring_price: 19366, competitor_price_diff: 2.3, trading_period: 8, cumulative_amount: 67659794, supplier_ranking: 11.3, item_amount: 4665587, item_ratio: 17.3, voc_count: 0, response_rate: 75.3, product_sales_period: '5년', payment_terms: '입고 후 30일 이내 현금 지급', alternative_supplier_count: 9 },
|
||||
},
|
||||
{
|
||||
id: 'preset-2',
|
||||
label: '총판·다수 (Type B)',
|
||||
item_name: '키보드',
|
||||
item_price: 34010, revenue: 25679490,
|
||||
dist: 'W', partners_yn: '다수', partners: 3,
|
||||
anchor: 31424, target: 33078, scenario: 'Scenario_A',
|
||||
card_data: { internet_min_price: 33716, anchoring_price: 31424, competitor_price_diff: 2.8, trading_period: 3, cumulative_amount: 34900205, supplier_ranking: 18.8, item_amount: 1643487, item_ratio: 6.4, voc_count: 1, response_rate: 74.5, product_sales_period: '2년', payment_terms: '월 2회 정산 (15일·말일 마감)', alternative_supplier_count: 7 },
|
||||
},
|
||||
{
|
||||
id: 'preset-3',
|
||||
label: '총판·단독 (Type C)',
|
||||
item_name: '콤부차 피치',
|
||||
item_price: 61390, revenue: 4536820,
|
||||
dist: 'W', partners_yn: '단독', partners: 1,
|
||||
anchor: 57071, target: 60075, scenario: 'Scenario_D',
|
||||
card_data: { internet_min_price: 59650, anchoring_price: 57071, competitor_price_diff: 3.7, trading_period: 1, cumulative_amount: 4942292, supplier_ranking: 42.1, item_amount: 199620, item_ratio: 4.4, voc_count: 0, response_rate: 69.5, product_sales_period: '5년', payment_terms: '월 2회 정산 (15일·말일 마감)', alternative_supplier_count: 10 },
|
||||
},
|
||||
{
|
||||
id: 'preset-4',
|
||||
label: '제조 (Type C)',
|
||||
item_name: '광감쇄기(SC Type)',
|
||||
item_price: 10600, revenue: 9014608,
|
||||
dist: 'M', partners_yn: '없음', partners: 0,
|
||||
anchor: 9862, target: 10492, scenario: 'Scenario_C',
|
||||
card_data: { internet_min_price: 10819, anchoring_price: 9862, competitor_price_diff: 3.9, trading_period: 3, cumulative_amount: 26421260, supplier_ranking: 50.5, item_amount: 2767484, item_ratio: 30.7, voc_count: 0, response_rate: 91.9, product_sales_period: '4년', payment_terms: '입고 완료 월 익월 15일 지급', alternative_supplier_count: 4 },
|
||||
},
|
||||
]
|
||||
|
||||
export const DIST_LABEL: Record<string, string> = { R: '유통', W: '총판', M: '제조' }
|
||||
@@ -0,0 +1,48 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
@theme {
|
||||
/* 콘솔 팔레트 — 파랑 = 인하/성공 (국내 시장 컨벤션: 파랑=하락) */
|
||||
--color-paper: #f5f6f8;
|
||||
--color-panel: #ffffff;
|
||||
--color-ink: #171b26;
|
||||
--color-muted: #68707f;
|
||||
--color-line: #e2e5eb;
|
||||
--color-blue: #1d4ed8; /* 인하·성공·주요 액션 */
|
||||
--color-blue-soft: #eef2ff;
|
||||
--color-amber: #b45309; /* 긴장도·주의 */
|
||||
--color-amber-soft: #fef3e2;
|
||||
--color-green: #067647; /* 협상완료 */
|
||||
--color-green-soft: #e7f6ee;
|
||||
--color-bot: #f0f2f6; /* 봇 말풍선 */
|
||||
|
||||
--font-body: "Pretendard Variable", Pretendard, ui-sans-serif, system-ui, sans-serif;
|
||||
--font-mono: "IBM Plex Mono", ui-monospace, monospace;
|
||||
}
|
||||
|
||||
html, body, #root {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--color-paper);
|
||||
color: var(--color-ink);
|
||||
font-family: var(--font-body);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
word-break: keep-all;
|
||||
}
|
||||
|
||||
/* 봇 응답 등장 */
|
||||
@keyframes rise {
|
||||
from { opacity: 0; transform: translateY(6px); }
|
||||
to { opacity: 1; transform: none; }
|
||||
}
|
||||
.msg-in { animation: rise 0.25s ease-out both; }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.msg-in { animation: none; }
|
||||
}
|
||||
|
||||
/* 가격 트랙 마커 이동 */
|
||||
.track-marker { transition: left 0.6s cubic-bezier(0.22, 1, 0.36, 1); }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.track-marker { transition: none; }
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
// NEGO_AGENT 서버 API — /api → :53117 (vite proxy)
|
||||
|
||||
import type { CardData, DemoCase } from '../content/cases'
|
||||
|
||||
export interface ChatMetadata {
|
||||
card_id: string | null
|
||||
q_value: number | null
|
||||
indicator_value: number | null
|
||||
indicator_range: 'PZ1' | 'PZ2' | 'PZ3' | null
|
||||
tension: number | null
|
||||
persona: string | null
|
||||
price: number | null
|
||||
iteration: number
|
||||
}
|
||||
|
||||
export interface ChatResponse {
|
||||
index: number
|
||||
script: string
|
||||
chat_end: boolean
|
||||
next_input_mode: 'confirm' | 'yes_no' | 'price' | 'null' | 'delivery_type'
|
||||
input_options: string[] | null
|
||||
step: string
|
||||
client_step: string | null
|
||||
chat_metadata: ChatMetadata | null
|
||||
}
|
||||
|
||||
export interface ChatBody {
|
||||
rq_type: string
|
||||
session_id: string
|
||||
step: string
|
||||
index: number
|
||||
user_input?: string | null
|
||||
item_price?: number
|
||||
revenue?: number
|
||||
dist?: string
|
||||
partners_yn?: string
|
||||
partners?: number
|
||||
anchor?: number
|
||||
target?: number
|
||||
initial?: number | null
|
||||
input?: number | null
|
||||
iteration?: number
|
||||
is_new_quote?: boolean
|
||||
profiling?: boolean
|
||||
card_data?: CardData
|
||||
}
|
||||
|
||||
export async function chat(body: ChatBody): Promise<ChatResponse> {
|
||||
const res = await fetch('/api/v1/nego/chat', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
if (!res.ok) throw new Error(`서버 응답 오류 (${res.status})`)
|
||||
return res.json()
|
||||
}
|
||||
|
||||
export async function invalidateSession(sessionId: string): Promise<void> {
|
||||
await fetch('/api/v1/nego/session/invalidate', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ session_id: sessionId, reason: '데모 재시작' }),
|
||||
})
|
||||
}
|
||||
|
||||
export async function serverAlive(): Promise<boolean> {
|
||||
try {
|
||||
const res = await fetch('/api/health')
|
||||
return res.ok
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 카드 변수 동적 산식 (하네스 build_card_data 계승):
|
||||
// 경쟁사가격반영 = max(100 × (1 − 앵커/입력가), 1)
|
||||
export function buildCardData(demoCase: DemoCase, price: number | null): CardData {
|
||||
const cd = { ...demoCase.card_data, anchoring_price: demoCase.anchor }
|
||||
if (price && price > 0) {
|
||||
cd.competitor_price_diff = Math.max(
|
||||
Math.round((100 * (1 - demoCase.anchor / price)) * 10) / 10, 1)
|
||||
}
|
||||
return cd
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
Reference in new issue
Block a user