[feat] agent·negodata: 협상카드 전술 데이터화(tactic JSONB·스크립트 파싱) + 발동규칙 정비
IMK QA 2건(BB9A 카드 중복·8AB0 중간값 오계산)의 근본 원인이 전술 하드코딩(_TACTICS 번호 매칭)이라 전술을 데이터로 옮기고, 발동을 유효성 검사로 바꿨다. 전술 정본 = 카드 스크립트의 마지막 가격 변수(파싱), 문장으로 알 수 없는 운영 규칙(closing·min_round)만 card.*.tactic JSONB. 세션 시작 시 card_specs 스냅샷 박제. 발동 유효성(하나라도 걸리면 그 라운드 미발동 — 클램프 폐지): 목표가 초과 / 협력사 제시가 이상 / 당사 직전 제안 미만(역행 금지, IMK 논의) / 재료 결측 / 필수 변수 결측(시장가 카드 requires — 토큰 노출 방지) / 이미 쓴 카드(played_card_numbers 공용 이력) - agent: 와일드=비종결·종결=전용 풀 분리(같은 카드 2회 구조적 차단), 발동 시 자기 제안가 기록(절충가 수렴), 진입 존 프로브(빈 덱 재사용 교착 방지), 낼 카드 전무 시 소진→종결, 무효 금액 카드는 설득 폴백도 금지(playable), 에디터 anchor_price 별칭 등록, 에러 재렌더 변수 치환 - backend: 카드 사용 기록을 step 휴리스틱→번호 prefix 판정(종결 발동 card:null 누락 해소) - negodata: 카드 상세 "협상 전술" 섹션(제시 가격 파싱 표시·종결 전용·최소 라운드) + tactic API 배선 - postgres-init: tactic 컬럼·시드(WC-03/05 closing, WC-04 min_round 2), 멱등 alter 로 dev 정본화 (번호 WC-0x 정규화, WC-01·03·NGC-010 구멘트 교체, WC-05 변수 middle_price 교정) 검증: agent 178 통과 · 시나리오 하네스 14케이스(BB9A·8AB0·역행 실수치 재현) · 랜덤 퍼즈 50협상 불변식 위반 0 (불변식: 카드 중복 금지·종결 카드 자리·타결가≤목표가·표시가=타결가·토큰 잔존 금지·종료 보장)
This commit is contained in:
1 parent
71ef28110b
commit
6f5d69b5cb
30 files changed
+1010
-174
No files matched your search
@@ -14,6 +14,7 @@ import type { CardUsageType } from './cardUsageType';
|
||||
import type { CardStatus } from './cardStatus';
|
||||
import type { CardDataCondition } from './cardDataCondition';
|
||||
import type { CardDataMemo } from './cardDataMemo';
|
||||
import type { CardDataTactic } from './cardDataTactic';
|
||||
import type { CardDataCreatedAt } from './cardDataCreatedAt';
|
||||
import type { CardDataUpdatedAt } from './cardDataUpdatedAt';
|
||||
|
||||
@@ -31,6 +32,7 @@ export interface CardData {
|
||||
status?: CardStatus;
|
||||
condition?: CardDataCondition;
|
||||
memo?: CardDataMemo;
|
||||
tactic?: CardDataTactic;
|
||||
created_at?: CardDataCreatedAt;
|
||||
updated_at?: CardDataUpdatedAt;
|
||||
success_rate?: number;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type CardDataTactic = unknown | null;
|
||||
@@ -15,6 +15,7 @@ export * from './cardDataMemo';
|
||||
export * from './cardDataName';
|
||||
export * from './cardDataNumber';
|
||||
export * from './cardDataScript';
|
||||
export * from './cardDataTactic';
|
||||
export * from './cardDataUpdatedAt';
|
||||
export * from './cardDataUserId';
|
||||
export * from './cardStatus';
|
||||
@@ -155,6 +156,7 @@ export * from './reqCreateCardMemo';
|
||||
export * from './reqCreateCardName';
|
||||
export * from './reqCreateCardNumber';
|
||||
export * from './reqCreateCardScript';
|
||||
export * from './reqCreateCardTactic';
|
||||
export * from './reqCreateCompanyUser';
|
||||
export * from './reqCreateItem';
|
||||
export * from './reqCreateItemCategory';
|
||||
@@ -215,6 +217,7 @@ export * from './reqUpdateCardName';
|
||||
export * from './reqUpdateCardNumber';
|
||||
export * from './reqUpdateCardScript';
|
||||
export * from './reqUpdateCardStatus';
|
||||
export * from './reqUpdateCardTactic';
|
||||
export * from './reqUpdateCardUsageType';
|
||||
export * from './reqUpdateCompanySettings';
|
||||
export * from './reqUpdateCompanySettingsSettings';
|
||||
|
||||
@@ -10,6 +10,7 @@ import type { ReqCreateCardScript } from './reqCreateCardScript';
|
||||
import type { ReqCreateCardEditScript } from './reqCreateCardEditScript';
|
||||
import type { ReqCreateCardCondition } from './reqCreateCardCondition';
|
||||
import type { ReqCreateCardMemo } from './reqCreateCardMemo';
|
||||
import type { ReqCreateCardTactic } from './reqCreateCardTactic';
|
||||
|
||||
export interface ReqCreateCard {
|
||||
is_wildcard?: boolean;
|
||||
@@ -22,4 +23,5 @@ export interface ReqCreateCard {
|
||||
status?: number;
|
||||
condition?: ReqCreateCardCondition;
|
||||
memo?: ReqCreateCardMemo;
|
||||
tactic?: ReqCreateCardTactic;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type ReqCreateCardTactic = unknown | null;
|
||||
@@ -12,6 +12,7 @@ import type { ReqUpdateCardUsageType } from './reqUpdateCardUsageType';
|
||||
import type { ReqUpdateCardStatus } from './reqUpdateCardStatus';
|
||||
import type { ReqUpdateCardCondition } from './reqUpdateCardCondition';
|
||||
import type { ReqUpdateCardMemo } from './reqUpdateCardMemo';
|
||||
import type { ReqUpdateCardTactic } from './reqUpdateCardTactic';
|
||||
|
||||
export interface ReqUpdateCard {
|
||||
name?: ReqUpdateCardName;
|
||||
@@ -22,4 +23,5 @@ export interface ReqUpdateCard {
|
||||
status?: ReqUpdateCardStatus;
|
||||
condition?: ReqUpdateCardCondition;
|
||||
memo?: ReqUpdateCardMemo;
|
||||
tactic?: ReqUpdateCardTactic;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type ReqUpdateCardTactic = unknown | null;
|
||||
@@ -13,16 +13,37 @@ import { type NegotiationCard, type CardTab, generateCardCode } from '../types';
|
||||
import { CardUsageType } from '@/api/generated/model';
|
||||
import { CARD_USAGE_TYPE_LABEL, CARD_USAGE_TYPE_OPTIONS } from '@/lib/enumLabels';
|
||||
import type { CardInput } from '../hooks/useCards';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import {
|
||||
CardScriptEditor,
|
||||
deserialize,
|
||||
serializeToText,
|
||||
serializeToMarker,
|
||||
hasConditionVariable,
|
||||
extractCondition,
|
||||
attachCondition,
|
||||
CONDITION_LABEL,
|
||||
} from '../editor';
|
||||
|
||||
// 제안가가 될 수 있는 변수 → 라벨. agent(tactics.OFFER_VARIABLES)와 동일 목록 — 스크립트의
|
||||
// 마지막 제안가 변수가 이 카드가 부를 금액이다(여기 없는 변수는 읽어주기 전용).
|
||||
const OFFER_VARIABLE_LABEL: Record<string, string> = {
|
||||
target_price: '목표가',
|
||||
anchoring_price: '앵커가',
|
||||
anchor_price: '앵커가',
|
||||
target_mid_price: '중간가 (앵커·목표의 중간)',
|
||||
middle_price: '절충가 (당사 직전 제안·제시가의 중간)',
|
||||
};
|
||||
|
||||
// 스크립트에서 제안가 변수를 파싱(마지막 매치) — agent parse_offer_variable 미러.
|
||||
function parseOfferLabel(editorScript: Descendant[]): string | null {
|
||||
const marker = serializeToMarker(editorScript);
|
||||
const found = [...marker.matchAll(/\{([a-z_]+)\}/g)]
|
||||
.map((m) => m[1])
|
||||
.filter((name) => name in OFFER_VARIABLE_LABEL);
|
||||
return found.length ? OFFER_VARIABLE_LABEL[found[found.length - 1]] : null;
|
||||
}
|
||||
|
||||
const schema = z.object({
|
||||
isWildcard: z.boolean(),
|
||||
usageType: z.number(),
|
||||
@@ -35,6 +56,8 @@ const schema = z.object({
|
||||
status: z.enum(['ACTIVE', 'INACTIVE']),
|
||||
triggerCondition: z.string(),
|
||||
memo: z.string(),
|
||||
closing: z.boolean(), // 종결 전용 — 라운드 상한·카드 소진 때의 마지막 한 방으로만
|
||||
minRound: z.number({ message: '최소 라운드를 숫자로 입력해 주세요.' }).int().min(1, '최소 라운드는 1 이상이어야 합니다.'),
|
||||
}).refine(
|
||||
// 조건 전략 칩을 넣었으면 조건 내용도 작성해야 한다(빈 상태로 저장 시 문구가 비어버림).
|
||||
(v) => !hasConditionVariable(v.editorScript) || serializeToText(v.conditionScript).trim().length > 0,
|
||||
@@ -73,6 +96,8 @@ function buildDefaults(
|
||||
status: card.status,
|
||||
triggerCondition: card.triggerCondition || '',
|
||||
memo: card.memo || '',
|
||||
closing: card.tactic?.closing ?? false,
|
||||
minRound: card.tactic?.min_round ?? 1,
|
||||
};
|
||||
}
|
||||
const wild = activeTab === 'WILD';
|
||||
@@ -86,6 +111,8 @@ function buildDefaults(
|
||||
status: 'ACTIVE',
|
||||
triggerCondition: '',
|
||||
memo: '',
|
||||
closing: false,
|
||||
minRound: 1,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -117,6 +144,8 @@ export function CardFormSheet({
|
||||
const isWildcard = watch('isWildcard');
|
||||
// 본문에 조건 전략 칩이 있으면 조건 내용 입력용 별도 에디터를 노출한다.
|
||||
const showConditionEditor = hasConditionVariable(watch('editorScript') || []);
|
||||
// 제시 가격 = 스크립트 파싱 결과(마지막 제안가 변수) — 입력이 아니라 표시(단일 진실은 스크립트).
|
||||
const offerLabel = parseOfferLabel(watch('editorScript') || []);
|
||||
|
||||
// 수정·삭제 게이팅 — 공용(기본 제공) 카드는 누구도 불가, 개인 카드는 본인 또는 최고관리자만(백엔드와 동일 규칙).
|
||||
const myUserId = useAuthStore((s) => s.user?.userId);
|
||||
@@ -142,6 +171,8 @@ export function CardFormSheet({
|
||||
usageType: v.usageType,
|
||||
triggerCondition: v.triggerCondition,
|
||||
memo: v.memo,
|
||||
// 항상 풀 객체로 전송 — 부분 전송(exclude_unset)이면 종결 해제가 DB 에 안 남는다.
|
||||
tactic: { min_round: v.minRound, closing: v.closing },
|
||||
};
|
||||
const kind = v.isWildcard ? '와일드카드' : '협상카드';
|
||||
try {
|
||||
@@ -358,6 +389,50 @@ export function CardFormSheet({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 협상 전술 — 제시 가격은 스크립트의 변수가 정하고(읽기 전용 표시), 운영 규칙만 입력받는다. */}
|
||||
<div className="space-y-3 p-3 bg-muted/40 rounded border border-border">
|
||||
<Typography variant="label" className="font-bold text-[10px] block">협상 전술</Typography>
|
||||
<div className="space-y-1">
|
||||
<Typography as="label" variant="small" className="font-semibold">제시 가격</Typography>
|
||||
<Typography as="p" variant="small" className="text-muted-foreground">
|
||||
{offerLabel ?? '없음 — 설득 전용 (가격 변수를 넣으면 그 값을 제시합니다)'}
|
||||
</Typography>
|
||||
<Typography as="p" variant="small" className="text-[10px] text-muted-foreground leading-snug">
|
||||
스크립트의 마지막 가격 변수가 협력사에게 제시(수락 시 타결)할 금액입니다.
|
||||
제시 가격이 목표가를 넘거나 협력사 제시가보다 높으면 이 카드는 그 라운드에 발동하지 않습니다.
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
|
||||
<div className="space-y-1">
|
||||
<div className="flex items-center justify-between">
|
||||
<Typography as="label" variant="small" className="font-semibold">종결 전용</Typography>
|
||||
<Controller
|
||||
control={control}
|
||||
name="closing"
|
||||
render={({ field }) => <Switch checked={field.value} onCheckedChange={field.onChange} />}
|
||||
/>
|
||||
</div>
|
||||
<Typography as="p" variant="small" className="text-[10px] text-muted-foreground leading-snug">
|
||||
켜면 협상 중반엔 아껴두고, 라운드 상한·카드 소진 시 마지막 제안으로만 발동합니다.
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<Typography as="label" variant="small" className="font-semibold">최소 라운드</Typography>
|
||||
<Input
|
||||
id="form-card-min-round"
|
||||
type="number"
|
||||
min={1}
|
||||
className="text-xs"
|
||||
{...register('minRound', { valueAsNumber: true })}
|
||||
/>
|
||||
<Typography as="p" variant="small" className="text-[10px] text-muted-foreground leading-snug">
|
||||
협력사가 가격을 이 횟수 이상 제시한 뒤부터 발동합니다. (기본 1 = 첫 제안부터)
|
||||
</Typography>
|
||||
{errors.minRound && <p className="text-[10px] text-rose-500">{errors.minRound.message}</p>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Wildcard-only fields */}
|
||||
{isWildcard && (
|
||||
<div className="space-y-4 p-3 bg-muted/40 rounded border border-border">
|
||||
|
||||
@@ -27,6 +27,7 @@ export type CardInput = {
|
||||
usageType: number; // usage_type(CardUsageType): 1=공통 2=신규견적전용 3=재견적전용
|
||||
triggerCondition?: string;
|
||||
memo?: string;
|
||||
tactic?: { min_round?: number; closing?: boolean }; // 전술 운영 규칙. 제안가는 스크립트 변수가 정한다
|
||||
};
|
||||
|
||||
// 서버 공통응답(result.success=false)을 한글 사유로 변환. 정상이면 null.
|
||||
@@ -50,6 +51,7 @@ function toReq(input: CardInput): ReqCreateCard {
|
||||
status: toCardStatusCode(input.status),
|
||||
condition: input.isWildcard ? input.triggerCondition : undefined,
|
||||
memo: input.isWildcard ? input.memo : undefined,
|
||||
tactic: input.tactic,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ export function mapCardData(c: CardData): NegotiationCard {
|
||||
creatorName: c.creator_name ?? undefined,
|
||||
successRate: c.success_rate ?? 0,
|
||||
usedCount: c.used_count ?? 0,
|
||||
tactic: (c.tactic as NegotiationCard['tactic']) ?? undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,13 @@ export interface NegotiationCard {
|
||||
creatorName?: string; // 등록자(작성자) 이름. 공용(user_id NULL) 카드는 없음
|
||||
successRate: number; // 카드 성공률(사용 세션 중 타결 비율). #12 순위
|
||||
usedCount: number; // 카드 사용 세션 수(표본)
|
||||
tactic?: CardTactic; // 전술 운영 규칙. 제안가는 스크립트 변수 파싱으로 결정(agent)
|
||||
}
|
||||
|
||||
// 카드 전술 운영 규칙(card.*.tactic JSONB) — 스크립트로 알 수 없는 것만 담는다.
|
||||
export interface CardTactic {
|
||||
min_round?: number; // 발동 가능 최소 라운드(협력사 가격 입력 횟수 기준)
|
||||
closing?: boolean; // 종결 전용 — 라운드 상한·카드 소진 때의 마지막 한 방으로만
|
||||
}
|
||||
|
||||
export type PageType = 'DASHBOARD' | 'STATISTICS' | 'PRODUCTS' | 'PARTNERS' | 'QUOTATION' | 'CARDS' | 'RENEGOTIATION' | 'MEMBERS' | 'SETTINGS' | 'DESIGN' | 'NOTIFICATIONS';
|
||||
Reference in new issue
Block a user