[feat] 협상 멘트 스타일 파이프라인(마커) + agent 카드 DB 소스 + supplier_items 연동
표현 아키텍처: agent 스크립트는 의미(텍스트)만 소유, 표현(굵기·색)은 프론트 소유.
Slate 는 negodata 에디터 내부에만 두고, 전송/저장은 마커 문자열 한 벌(구버전의 리치텍스트 이중관리 폐기).
- 트랙 A (negodata): serializeToMarker 추가 — Slate 마크(bold/underline/color)를 **/__/{{토큰}} 로
인코딩해 nego_cards.script 저장. edit_script(Slate 원본)는 재편집 전용. 고정 3색 → 시맨틱 토큰(강조/안내).
- 트랙 B (agent): 카드 멘트 DB 소스 — ICardScriptRepository/CardScriptDbRepository(port+adapter),
ScriptRepository.resolve_card_script 가 cards.source_type=backoffice_db 면 card.nego_cards.script 우선,
없으면 파일 폴백. action_id→card_id→nego_cards.number 매칭.
- 트랙 C (양 프론트): renderEmphasis 재귀 파서 — **굵게**·__밑줄__·{{강조|빨강}}·{{안내|파랑}} 중첩 렌더.
색은 시맨틱 토큰→디자인 토큰 클래스(다크모드 안전). negodata tokens.css 에 --info 신설. CardTable 미리보기 적용.
- supplier_items 연동: 유통코드=supplier_items.supply_type(→quotations.supplier_type 폴백),
파트너유형=상품별 매핑 협력사 수(→세션 이력 폴백).
- 가격 수용률: 기존 공급가(item_price) 기준 양보율로 정정 — 첫 라운드부터 실값(첫 제시가 기준 0 아님).
테스트: agent 86/86, 공급사 frontend·negodata front tsc 통과.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dc0e78ec73
commit
1c8c4254a6
24 files changed
+509
-45
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { DataTable } from '@/components/ui/data-table';
|
||||
import { renderEmphasis } from '@/lib/emphasis';
|
||||
import type { NegotiationCard } from '../types';
|
||||
|
||||
type CardTableProps = {
|
||||
@@ -59,7 +60,8 @@ export function CardTable({ data, onEdit, footer }: CardTableProps) {
|
||||
mobileBlock: true, // 긴 미리보기 블록 → 모바일 카드뷰에서 라벨 아래 풀폭
|
||||
cell: (card) => (
|
||||
<div className="max-w-[22rem] truncate bg-muted/20 px-2 py-1 rounded border border-border/30 text-[11px] leading-snug">
|
||||
{card.scriptPreview}
|
||||
{/* 마커(**굵게**·{{색}})를 스타일로 렌더 — 표 미리보기에 원시 마커가 보이지 않게 */}
|
||||
{renderEmphasis(card.scriptPreview)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export { CardScriptEditor } from './CardScriptEditor';
|
||||
// deserialize() 는 항상 새 배열을 반환 → Slate initialValue 로 안전. 공용 mutable 상수는 export 하지 않는다.
|
||||
export { deserialize, serializeToText } from './slate';
|
||||
export { deserialize, serializeToText, serializeToMarker } from './slate';
|
||||
export { CARD_VARIABLES } from './variables';
|
||||
@@ -96,6 +96,38 @@ function serializeNode(node: Descendant): string {
|
||||
return node.text;
|
||||
}
|
||||
|
||||
// ── 직렬화: Slate 값 → 마커 문자열(script) ──────────────────
|
||||
// bold/underline/color 마크를 경량 마커로 인코딩해 저장한다(edit_script=Slate 원본은 재편집용).
|
||||
// agent 는 이 문자열을 불투명 텍스트로 전달하고, 각 프론트 emphasis.tsx 가 마커를 렌더한다.
|
||||
// 고정 팔레트(검정/빨강/파랑) → 시맨틱 토큰. 검정(#151515)은 기본이라 마커 없음.
|
||||
const COLOR_TO_TOKEN: Record<string, string> = {
|
||||
'#ED2024': '강조', // 빨강
|
||||
'#4880EF': '안내', // 파랑
|
||||
};
|
||||
|
||||
export function serializeToMarker(nodes: Descendant[]): string {
|
||||
return nodes.map(serializeMarkerNode).join('\n');
|
||||
}
|
||||
|
||||
function serializeMarkerNode(node: Descendant): string {
|
||||
if (SlateElement.isElement(node)) {
|
||||
if (node.type === 'variable') return applyMarks(`{${node.name}}`, node.children[0]);
|
||||
return node.children.map(serializeMarkerNode).join('');
|
||||
}
|
||||
return applyMarks(node.text, node);
|
||||
}
|
||||
|
||||
// 텍스트/변수 리프의 마크를 마커로 감싼다. 중첩 순서: 색(바깥) → 굵게 → 밑줄(안). 빈 문자열은 그대로.
|
||||
function applyMarks(text: string, leaf?: CustomText): string {
|
||||
if (!text || !leaf) return text;
|
||||
let s = text;
|
||||
if (leaf.underline) s = `__${s}__`;
|
||||
if (leaf.bold) s = `**${s}**`;
|
||||
const token = leaf.color ? COLOR_TO_TOKEN[leaf.color] : undefined;
|
||||
if (token) s = `{{${token}|${s}}}`;
|
||||
return s;
|
||||
}
|
||||
|
||||
// ── 역직렬화: edit_script(JSON) 또는 평문(script) → Slate 값 ──
|
||||
// 저장된 edit_script 가 있으면 그대로, 없으면(레거시 평문 카드) {name} 토큰을 변수 노드로 복원.
|
||||
// Slate 는 initialValue 를 레퍼런스로 직접 변경하므로 항상 새 배열을 돌려준다
|
||||
|
||||
@@ -11,7 +11,7 @@ import type { ReqCreateCard } from '@/api/generated/model/reqCreateCard';
|
||||
import type { ResCard } from '@/api/generated/model/resCard';
|
||||
import type { NegotiationCard } from '@/types';
|
||||
import { mapCardData, toCardStatusCode } from '../types';
|
||||
import { serializeToText } from '../editor';
|
||||
import { serializeToMarker } from '../editor';
|
||||
|
||||
// 카드 폼이 넘기는 입력값(편집/생성 공통).
|
||||
// 스크립트는 Slate JSON(editorScript)을 정본으로 받고, 평문 script 는 저장 시 직렬화로 파생한다.
|
||||
@@ -40,8 +40,8 @@ function toReq(input: CardInput): ReqCreateCard {
|
||||
usage_type: input.usageType,
|
||||
name: input.title,
|
||||
number: input.code,
|
||||
script: serializeToText(input.editorScript), // 평문 미리보기({변수} 토큰 포함)
|
||||
edit_script: input.editorScript, // Slate JSON 원본
|
||||
script: serializeToMarker(input.editorScript), // 마커 문자열(굵게·색 인코딩 + {변수} 토큰)
|
||||
edit_script: input.editorScript, // Slate JSON 원본(재편집 전용)
|
||||
status: toCardStatusCode(input.status),
|
||||
condition: input.isWildcard ? input.triggerCondition : undefined,
|
||||
memo: input.isWildcard ? input.memo : undefined,
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Typography } from '@/components/ui/typography';
|
||||
import { StatusPill, sessionStatusTone } from './StatusPill';
|
||||
import { type Product, type Partner, sessionStatusLabel } from '../../types';
|
||||
import { maskPrices } from '@/lib/utils';
|
||||
import { renderEmphasis } from '@/lib/emphasis';
|
||||
|
||||
export function ChatTab({
|
||||
serverSessions,
|
||||
@@ -158,7 +159,7 @@ function BotBubble({
|
||||
)}
|
||||
{m.script && (
|
||||
<Typography as="p" variant="small" className="text-xs whitespace-pre-line leading-relaxed text-inherit">
|
||||
{maskPrices(m.script)}
|
||||
{renderEmphasis(maskPrices(m.script))}
|
||||
</Typography>
|
||||
)}
|
||||
<UsedCardBox
|
||||
|
||||
Reference in new issue
Block a user