저장소 재편 — results/ 폐지, eval/<지표>/ 통합, 최저가 탐색 엔진 server/ 이동
- results/ 를 없애고 지표별 eval/<NN_지표>/ 에 측정 코드·result.json·detail.jsonl·실행 원본·provenance.md 를 모음 (요약은 eval/SUMMARY.md) - 입력은 testdata/ 로 통일: 0_server_logs_frozen(동결본)·2_total_data(②)·8_items1000_master(⑧ 시험 데이터) - ⑧ 은 입력 8_items1000_master.xlsx 1개 + 검수 완료 items1000.xlsx 1개만 남김 (실행 원본·캐시·모집단은 저장소 밖 보관) - prism_core + capture_local → server/services/price_search (데모 API 와 측정 하네스가 같은 엔진 사용, sys.path 해킹 제거) - 엔진 의존성(selectolax·Pillow·openpyxl) server/requirements.txt 로 통합, docker-compose 는 eval·testdata 만 마운트 - prism_core 주석·독스트링 1~2줄로 축약 (AST 동일성 검증) - 데모 콘솔 최저가 검색 패널(PriceSearchPanel) 추가 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
9b2f49eb40
commit
cb737b9a11
328 files changed
+15223
-159210
No files matched your search
+40
-6
@@ -5,6 +5,7 @@ import { CasePanel } from './components/CasePanel'
|
||||
import { PricePanel } from './components/PricePanel'
|
||||
import { ChatPanel, type Msg } from './components/ChatPanel'
|
||||
import { Dashboard } from './components/Dashboard'
|
||||
import { PriceSearchPanel } from './components/PriceSearchPanel'
|
||||
|
||||
export interface NegoState {
|
||||
step: string
|
||||
@@ -28,7 +29,22 @@ const IDLE: NegoState = {
|
||||
mode: 'null', options: [], done: false,
|
||||
}
|
||||
|
||||
type View = 'nego' | 'price'
|
||||
// 화면 ↔ 경로: '/' = 협상 데모, '/price' = 최저가 탐색 (라우터 없이 history API만 사용)
|
||||
const VIEW_PATH: Record<View, string> = { nego: '/', price: '/price' }
|
||||
const viewFromPath = (): View => (window.location.pathname === VIEW_PATH.price ? 'price' : 'nego')
|
||||
|
||||
export default function App() {
|
||||
const [view, setViewState] = useState<View>(viewFromPath)
|
||||
const setView = useCallback((next: View) => {
|
||||
setViewState(next)
|
||||
if (window.location.pathname !== VIEW_PATH[next]) window.history.pushState(null, '', VIEW_PATH[next])
|
||||
}, [])
|
||||
useEffect(() => {
|
||||
const onPop = () => setViewState(viewFromPath())
|
||||
window.addEventListener('popstate', onPop)
|
||||
return () => window.removeEventListener('popstate', onPop)
|
||||
}, [])
|
||||
const [demoCase, setDemoCase] = useState<DemoCase | null>(null)
|
||||
const [nego, setNego] = useState<NegoState>(IDLE)
|
||||
const [messages, setMessages] = useState<Msg[]>([])
|
||||
@@ -156,11 +172,25 @@ export default function App() {
|
||||
return (
|
||||
<div className="flex min-h-dvh flex-col min-[960px]:h-dvh">
|
||||
<header className="flex items-center justify-between bg-base-100 px-6 py-3.5">
|
||||
<div className="flex items-baseline gap-3">
|
||||
<h1 className="text-xl font-extrabold tracking-tight">NEGO 협상 콘솔</h1>
|
||||
<span className="hidden text-sm text-base-content/55 sm:inline">
|
||||
구매 협상 에이전트 시연 — 당신은 공급사입니다
|
||||
</span>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="flex items-baseline gap-3">
|
||||
<h1 className="text-xl font-extrabold tracking-tight">NEGO 협상 콘솔</h1>
|
||||
<span className="hidden text-sm text-base-content/55 lg:inline">
|
||||
{view === 'nego' ? '구매 협상 에이전트 시연 — 당신은 공급사입니다' : '인터넷 최저가 탐색 테스트'}
|
||||
</span>
|
||||
</div>
|
||||
<nav className="flex gap-1 rounded-field bg-base-200 p-1" aria-label="화면 전환">
|
||||
{([['nego', '협상 데모'], ['price', '최저가 탐색']] as const).map(([key, label]) => (
|
||||
<button
|
||||
key={key}
|
||||
type="button"
|
||||
className={`btn btn-xs border-0 ${view === key ? 'bg-base-100 shadow-none' : 'btn-ghost text-base-content/55'}`}
|
||||
onClick={() => setView(key)}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
))}
|
||||
</nav>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<span
|
||||
@@ -175,7 +205,11 @@ export default function App() {
|
||||
</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-[290px_minmax(0,1fr)_330px]">
|
||||
{/* 두 화면 모두 마운트 유지 — 탭 전환 시 협상 세션·검색 결과가 사라지지 않는다 */}
|
||||
<main className={`mx-auto w-full max-w-screen-2xl flex-1 gap-4 p-4 min-[960px]:min-h-0 ${view === 'price' ? 'flex flex-col min-[960px]:flex-row' : 'hidden'}`}>
|
||||
<PriceSearchPanel />
|
||||
</main>
|
||||
<main className={`mx-auto w-full max-w-screen-2xl flex-1 grid-cols-1 gap-4 p-4 min-[960px]:min-h-0 min-[960px]:grid-cols-[290px_minmax(0,1fr)_330px] ${view === 'nego' ? 'grid' : 'hidden'}`}>
|
||||
<aside className="flex flex-col gap-4 min-[960px]:min-h-0 min-[960px]:overflow-y-auto">
|
||||
<CasePanel
|
||||
cases={DEMO_CASES}
|
||||
|
||||
@@ -0,0 +1,313 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { priceSearch, type PriceSnapshot } from '../lib/api'
|
||||
|
||||
const MALL_LABELS: Record<string, string> = {
|
||||
danawa: '다나와', enuri: '에누리', gsshop: 'GS샵',
|
||||
}
|
||||
|
||||
const STATE_LABELS: Record<string, string> = {
|
||||
MATCHED: '매칭', NO_MATCH: '동일상품 없음', EMPTY: '검색 0건',
|
||||
BLOCKED: '차단됨', UNAVAILABLE: '접속 실패',
|
||||
}
|
||||
|
||||
// veto 사유 한글화 — prism_core/identity.py 의 반환 규약과 짝
|
||||
function vetoLabel(reason: string): string {
|
||||
if (reason === 'brand') return '브랜드 불일치'
|
||||
if (reason === 'empty') return '이름 없음'
|
||||
const [kind, arg] = reason.split(':', 2)
|
||||
if (kind === 'model') return `모델 누락 (${arg})`
|
||||
if (kind === 'var-miss') return `변형어 누락 (${arg})`
|
||||
if (kind === 'var-extra') return `변형어 초과 (${arg})`
|
||||
if (kind === 'spec') return `규격 충돌 (${arg})`
|
||||
return reason
|
||||
}
|
||||
|
||||
type PoolFilter = 'all' | 'accepted' | 'rejected'
|
||||
|
||||
export function PriceSearchPanel() {
|
||||
const [name, setName] = useState('')
|
||||
const [judge, setJudge] = useState<'ai' | 'local'>('ai')
|
||||
const [keywordRefine, setKeywordRefine] = useState(false)
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [elapsed, setElapsed] = useState(0)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [snap, setSnap] = useState<PriceSnapshot | null>(null)
|
||||
const [filter, setFilter] = useState<PoolFilter>('all')
|
||||
const abortRef = useRef<AbortController | null>(null)
|
||||
|
||||
// 검색 경과 시간 — 몰 응답이 5~60초 걸리므로 진행이 살아있음을 보여준다
|
||||
useEffect(() => {
|
||||
if (!busy) return
|
||||
setElapsed(0)
|
||||
const t = setInterval(() => setElapsed((s) => s + 1), 1000)
|
||||
return () => clearInterval(t)
|
||||
}, [busy])
|
||||
|
||||
const run = async () => {
|
||||
const q = name.trim()
|
||||
if (q.length < 2 || busy) return
|
||||
const ctrl = new AbortController()
|
||||
abortRef.current = ctrl
|
||||
setBusy(true)
|
||||
setError(null)
|
||||
setSnap(null)
|
||||
setFilter('all')
|
||||
try {
|
||||
setSnap(await priceSearch({ product_name: q, judge, keyword_refine: keywordRefine }, ctrl.signal))
|
||||
} catch (e) {
|
||||
if (e instanceof DOMException && e.name === 'AbortError') setError('검색을 취소했습니다')
|
||||
else setError(e instanceof Error ? e.message : '요청 실패')
|
||||
} finally {
|
||||
setBusy(false)
|
||||
abortRef.current = null
|
||||
}
|
||||
}
|
||||
|
||||
const cancel = () => abortRef.current?.abort()
|
||||
|
||||
const pool = snap?.pool ?? []
|
||||
const shown = pool
|
||||
.filter((p) => (filter === 'all' ? true : filter === 'accepted' ? p.accepted : !p.accepted))
|
||||
.slice()
|
||||
.sort((a, b) => Number(b.accepted) - Number(a.accepted) || (b.ai_score ?? 0) - (a.ai_score ?? 0))
|
||||
const acceptedN = pool.filter((p) => p.accepted).length
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex w-full max-w-screen-xl flex-1 flex-col gap-4 min-[960px]:min-h-0 min-[960px]:flex-row">
|
||||
{/* ── 검색 설정 ─────────────────────────────── */}
|
||||
<section className="rounded-box bg-base-100 p-5 min-[960px]:w-[290px] min-[960px]:shrink-0 min-[960px]:self-start">
|
||||
<h2 className="text-[13px] font-semibold text-base-content/55">최저가 탐색</h2>
|
||||
<form
|
||||
className="mt-3 flex flex-col gap-3"
|
||||
onSubmit={(e) => { e.preventDefault(); run() }}
|
||||
>
|
||||
<label className="flex flex-col gap-1.5">
|
||||
<span className="text-[13px] font-medium">상품명</span>
|
||||
<input
|
||||
type="text"
|
||||
className="input input-bordered w-full bg-base-200 text-[14px]"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
placeholder="예: 소니 WH-1000XM5"
|
||||
disabled={busy}
|
||||
/>
|
||||
</label>
|
||||
<label className="flex flex-col gap-1.5">
|
||||
<span className="text-[13px] font-medium">동일상품 판정기</span>
|
||||
<select
|
||||
className="select select-bordered w-full bg-base-200 text-[14px]"
|
||||
value={judge}
|
||||
onChange={(e) => setJudge(e.target.value as 'ai' | 'local')}
|
||||
disabled={busy}
|
||||
>
|
||||
<option value="ai">AI (OpenAI — 키 없으면 로컬 폴백)</option>
|
||||
<option value="local">로컬 (텍스트 검증, LLM 불필요)</option>
|
||||
</select>
|
||||
</label>
|
||||
<label className="flex cursor-pointer items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
className="checkbox checkbox-sm checkbox-primary"
|
||||
checked={keywordRefine}
|
||||
onChange={(e) => setKeywordRefine(e.target.checked)}
|
||||
disabled={busy}
|
||||
/>
|
||||
<span className="text-[13px]">LLM 검색어 재정제</span>
|
||||
</label>
|
||||
{keywordRefine && (
|
||||
<p className="text-xs leading-relaxed text-base-content/55">
|
||||
룰 재정제가 전부 0매칭일 때만 OpenAI 호출이 발생합니다.
|
||||
</p>
|
||||
)}
|
||||
{busy ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<button type="button" className="btn flex-1" onClick={cancel}>
|
||||
취소
|
||||
</button>
|
||||
<span className="num text-[13px] text-base-content/55">{elapsed}초</span>
|
||||
</div>
|
||||
) : (
|
||||
<button type="submit" className="btn btn-primary" disabled={name.trim().length < 2}>
|
||||
최저가 탐색
|
||||
</button>
|
||||
)}
|
||||
</form>
|
||||
</section>
|
||||
|
||||
{/* ── 진행 · 결과 ───────────────────────────── */}
|
||||
<div className="flex min-w-0 flex-1 flex-col gap-4 min-[960px]:min-h-0 min-[960px]:overflow-y-auto">
|
||||
{busy && (
|
||||
<section className="rounded-box bg-base-100 p-5">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="loading loading-spinner loading-sm text-primary" aria-hidden />
|
||||
<div>
|
||||
<p className="text-[14px] font-medium">다나와 · 에누리 · GS샵 검색 중</p>
|
||||
<p className="mt-0.5 text-[13px] text-base-content/55">
|
||||
검색어 재정제 라운드에 따라 최대 1분쯤 걸릴 수 있습니다.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{error && !busy && (
|
||||
<section className="rounded-box bg-base-100 p-5">
|
||||
<p className="text-[14px] font-medium text-error">{error}</p>
|
||||
<p className="mt-1 text-[13px] text-base-content/55">
|
||||
상품명을 확인하고 다시 시도해 주세요. 서버(:3300)가 레포 체크아웃에서 떠 있어야 합니다.
|
||||
</p>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{!busy && !error && !snap && (
|
||||
<section className="rounded-box bg-base-100 p-5">
|
||||
<h2 className="text-[13px] font-semibold text-base-content/55">사용 방법</h2>
|
||||
<p className="mt-2 text-[14px] leading-relaxed text-base-content/70">
|
||||
상품명을 입력하면 다나와 · 에누리 · GS샵을 검색해 동일상품 판정과 식별 게이트를
|
||||
거친 <b>인터넷 최저가</b>를 찾습니다. 아래 후보 풀에서 각 후보가 왜 채택·기각됐는지
|
||||
(AI 점수, veto 사유) 그대로 확인할 수 있습니다.
|
||||
</p>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{snap && !busy && (
|
||||
<>
|
||||
{/* 결과 요약 */}
|
||||
<section className="rounded-box bg-base-100 p-5">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span
|
||||
className={`rounded-full px-2.5 py-0.5 text-[13px] font-semibold ${
|
||||
snap.outcome === 'found' ? 'bg-success/10 text-success' : 'bg-error/10 text-error'
|
||||
}`}
|
||||
>
|
||||
{snap.outcome === 'found' ? '탐색 성공' : '미탐색'}
|
||||
</span>
|
||||
<span className="text-[13px] text-base-content/55">
|
||||
판정기 {snap.judge_used === 'ai' ? 'AI' : '로컬'}
|
||||
{snap.judge_fallback && ' (키 없음 — 로컬 폴백)'}
|
||||
{' · '}시도 {snap.attempts}라운드 · 후보 {snap.candidates}건 ·{' '}
|
||||
<span className="num">{snap.elapsed_sec}</span>초
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{snap.outcome === 'found' ? (
|
||||
<div className="mt-3">
|
||||
<p className="num text-[28px] font-bold tracking-tight">
|
||||
{snap.lowest_price?.toLocaleString()}
|
||||
<span className="ml-0.5 text-lg font-semibold text-base-content/55">원</span>
|
||||
</p>
|
||||
{(() => {
|
||||
const m = snap.malls.find((x) => x.source === snap.lowest_source && x.price === snap.lowest_price)
|
||||
return m ? (
|
||||
<div className="mt-1.5 text-[14px]">
|
||||
<p className="font-medium">{m.name}</p>
|
||||
<p className="mt-0.5 text-[13px] text-base-content/55">
|
||||
{MALL_LABELS[m.source] ?? m.source}
|
||||
{m.shipping_fee != null && <> · 배송비 <span className="num">{m.shipping_fee.toLocaleString()}</span>원</>}
|
||||
{m.ai_score != null && <> · AI유사도 <span className="num">{m.ai_score}</span></>}
|
||||
{m.detail_url && (
|
||||
<>
|
||||
{' · '}
|
||||
<a href={m.detail_url} target="_blank" rel="noreferrer" className="text-primary underline">
|
||||
상품 페이지 열기
|
||||
</a>
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
) : null
|
||||
})()}
|
||||
</div>
|
||||
) : (
|
||||
<p className="mt-3 text-[14px] leading-relaxed text-base-content/70">
|
||||
{snap.abstain_reason === 'ai_match_vetoed'
|
||||
? 'AI는 매칭 후보를 찾았지만 식별 게이트가 전부 기각했습니다 — 아래 후보 풀에서 사유를 확인하세요.'
|
||||
: '세 몰의 검색 결과에서 동일 상품을 찾지 못했습니다.'}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{/* 몰별 상태 */}
|
||||
<div className="mt-4 grid grid-cols-3 gap-2">
|
||||
{snap.malls.map((m) => (
|
||||
<div key={m.source} className="rounded-field bg-base-200 px-3 py-2">
|
||||
<p className="text-[13px] font-medium">{MALL_LABELS[m.source] ?? m.source}</p>
|
||||
<p className={`mt-0.5 text-[13px] ${m.state_name === 'MATCHED' ? 'text-success' : 'text-base-content/55'}`}>
|
||||
{STATE_LABELS[m.state_name] ?? m.state_name}
|
||||
{m.price != null && <span className="num"> · {m.price.toLocaleString()}원</span>}
|
||||
</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* 후보 풀 */}
|
||||
<section className="rounded-box bg-base-100 p-5">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<h2 className="text-[13px] font-semibold text-base-content/55">
|
||||
후보 풀 — 최종 라운드 검색어 “{snap.query}”
|
||||
</h2>
|
||||
<div className="flex gap-1" role="group" aria-label="후보 필터">
|
||||
{([['all', `전체 ${pool.length}`], ['accepted', `통과 ${acceptedN}`], ['rejected', `기각 ${pool.length - acceptedN}`]] as const).map(([key, label]) => (
|
||||
<button
|
||||
key={key}
|
||||
type="button"
|
||||
className={`btn btn-xs ${filter === key ? 'btn-primary' : 'btn-ghost bg-base-200'}`}
|
||||
onClick={() => setFilter(key)}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{shown.length === 0 ? (
|
||||
<p className="mt-3 text-[13px] text-base-content/55">
|
||||
{pool.length === 0 ? '검색 결과 후보가 없습니다.' : '이 필터에 해당하는 후보가 없습니다.'}
|
||||
</p>
|
||||
) : (
|
||||
<div className="mt-3 overflow-x-auto">
|
||||
<table className="table table-sm w-full">
|
||||
<thead>
|
||||
<tr className="text-[12px] text-base-content/55">
|
||||
<th className="font-medium">몰</th>
|
||||
<th className="font-medium">후보명</th>
|
||||
<th className="text-right font-medium">가격</th>
|
||||
<th className="text-right font-medium">AI</th>
|
||||
<th className="font-medium">게이트</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{shown.map((p, i) => (
|
||||
<tr key={i} className={p.accepted ? '' : 'text-base-content/45'}>
|
||||
<td className="whitespace-nowrap text-[13px]">{MALL_LABELS[p.source] ?? p.source}</td>
|
||||
<td className="min-w-48 text-[13px] leading-snug">{p.name}</td>
|
||||
<td className="num whitespace-nowrap text-right text-[13px]">
|
||||
{p.price != null ? p.price.toLocaleString() : '—'}
|
||||
</td>
|
||||
<td className="num whitespace-nowrap text-right text-[13px]">{p.ai_score ?? '—'}</td>
|
||||
<td className="text-[12px]">
|
||||
{p.accepted ? (
|
||||
<span className="rounded-full bg-success/10 px-2 py-0.5 font-semibold text-success">통과</span>
|
||||
) : (
|
||||
<span className="flex flex-wrap gap-1">
|
||||
{(p.veto.length ? p.veto : p.ai_match ? [] : ['ai']).map((r, j) => (
|
||||
<span key={j} className="whitespace-nowrap rounded-full bg-base-200 px-2 py-0.5">
|
||||
{r === 'ai' ? 'AI 불일치' : vetoLabel(r)}
|
||||
</span>
|
||||
))}
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -80,6 +80,66 @@ export async function fetchCards(): Promise<CardCatalogResponse> {
|
||||
return res.json()
|
||||
}
|
||||
|
||||
// ---- 최저가 탐색 테스트 (/v1/price/search — 로컬 체크아웃 전용 라우터) ----
|
||||
|
||||
export interface PoolEntry {
|
||||
source: string
|
||||
name: string
|
||||
price: number | null
|
||||
ai_match: boolean
|
||||
ai_score: number | null
|
||||
veto: string[]
|
||||
accepted: boolean
|
||||
}
|
||||
|
||||
export interface MallRow {
|
||||
source: string
|
||||
state: string
|
||||
state_name: string
|
||||
confirmed: boolean
|
||||
price: number | null
|
||||
name: string | null
|
||||
detail_url: string | null
|
||||
shipping_fee: number | null
|
||||
ai_score: number | null
|
||||
}
|
||||
|
||||
export interface PriceSnapshot {
|
||||
product_code: string
|
||||
query: string
|
||||
outcome: 'found' | 'not_found'
|
||||
lowest_price: number | null
|
||||
lowest_source: string | null
|
||||
malls: MallRow[]
|
||||
elapsed_sec: number
|
||||
candidates: number
|
||||
ai_matched: number
|
||||
attempts: number
|
||||
pool: PoolEntry[]
|
||||
abstain_reason: string | null
|
||||
judge_used: 'ai' | 'local'
|
||||
judge_fallback: boolean
|
||||
keyword_refine_used: boolean
|
||||
}
|
||||
|
||||
export interface PriceSearchBody {
|
||||
product_name: string
|
||||
judge: 'ai' | 'local'
|
||||
keyword_refine: boolean
|
||||
}
|
||||
|
||||
export async function priceSearch(body: PriceSearchBody, signal?: AbortSignal): Promise<PriceSnapshot> {
|
||||
const res = await fetch('/api/v1/price/search', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
signal,
|
||||
})
|
||||
if (res.status === 404) throw new Error('최저가 탐색 라우터가 꺼져 있습니다 — 레포 체크아웃에서 서버를 실행하세요')
|
||||
if (!res.ok) throw new Error(`서버 응답 오류 (${res.status})`)
|
||||
return res.json()
|
||||
}
|
||||
|
||||
export async function serverAlive(): Promise<boolean> {
|
||||
try {
|
||||
const res = await fetch('/api/health')
|
||||
|
||||
Reference in new issue
Block a user