import type { AgentResult, CustomerMaster, Demand } from "../types"; import type { DeliveryResult, FeasibilityResult, RatingResult, RndResult } from "./rules"; import { computeCreditGap } from "./rules"; import { customer } from "../mock/customer"; import { wan } from "./format"; export interface OrderMock { orderNo: string; itemSummary: string; amount: number; deliveryDate: string; } export interface SummaryResult { overall: "评审通过" | "评审不通过"; rows: Array<{ agent: string; conclusion: string; keyEvidence: string }>; suggestions: string[]; creditGap: ReturnType | null; order: OrderMock | null; } /** 第四幕:主智能体汇总 + 订单 / 建议(规格 2.4) */ export function summarize( demand: Demand, feasibility: FeasibilityResult, rnd: RndResult | null, delivery: DeliveryResult, rating: RatingResult, customerOverride?: CustomerMaster, ): SummaryResult { const rows = [ { agent: "可行性", conclusion: feasibility.category, keyEvidence: `${demand.parsed.productType}命中 ${feasibility.category === "非标品" ? "R-可行-2" : "R-可行-1"}` }, ...(rnd ? [{ agent: "新品研发评审", conclusion: rnd.pass ? "通过" : "不通过", keyEvidence: rnd.items.map((i) => i.actual ?? "—").join(" / ") }] : []), { agent: "交期评审", conclusion: delivery.pass ? "通过" : "不通过", keyEvidence: `负荷 78%;采购+生产 ${delivery.daysToDelivery} 天内可覆盖` }, { agent: "客户评级", conclusion: rating.pass ? "通过" : "不通过", keyEvidence: `记分 ${rating.total} ${rating.pass ? "≥" : "<"} 90` }, ]; const allPass = feasibility !== null && (rnd ? rnd.pass : true) && delivery.pass && rating.pass; const suggestions: string[] = [...delivery.suggestions]; let creditGap: ReturnType | null = null; if (!rating.pass && rating.items[1].score === 0) { creditGap = computeCreditGap(demand, customerOverride ?? customer); suggestions.push( `建议发起客户临时授信:精确缺口 ${wan(creditGap.gap)} 万,建议授信 ≥ ${wan(creditGap.suggested)} 万(含缓冲)`, `处理路径:${creditGap.path}`, ); } const order: OrderMock | null = allPass ? { orderNo: "SO-2610-0001", itemSummary: `${demand.parsed.productType} ${demand.parsed.quantity} 个 @ ${demand.parsed.unitPrice.toLocaleString("zh-CN")} 元`, amount: demand.parsed.quantity * demand.parsed.unitPrice, deliveryDate: demand.parsed.deliveryDate, } : null; return { overall: allPass ? "评审通过" : "评审不通过", rows, suggestions, creditGap, order }; } export type { AgentResult };