Open-World: добавить staleness risk proxy в бизнес-обзор

This commit is contained in:
2026-05-04 10:43:10 +03:00
parent bf3ae110ef
commit 3a28709ce4
9 changed files with 292 additions and 16 deletions
@@ -470,6 +470,9 @@ function headlineFor(mode: AssistantMcpDiscoveryAnswerMode, pilot: AssistantMcpD
if (overview.inventory_turnover_proxy) {
families.push("оборотный proxy склада");
}
if (overview.inventory_staleness_risk_proxy) {
families.push("staleness risk proxy склада");
}
const unknownFamilies = [overview.trading_margin_proxy ? "чистая прибыль/точная маржа" : "прибыль/маржа"];
if (!overview.tax_position) {
unknownFamilies.push("НДС");
@@ -670,6 +673,7 @@ function buildMustNotClaim(pilot: AssistantMcpDiscoveryPilotExecutionContract):
claims.push("Do not present open-settlement concentration as contractual due-date aging or confirmed overdue debt.");
claims.push("Do not present an inventory snapshot or purchase-date aging signal as turnover, obsolescence, liquidation value, or full inventory health.");
claims.push("Do not present business overview inventory turnover proxy as full inventory liquidity, FIFO turnover, obsolescence analysis, or liquidation value.");
claims.push("Do not present business overview inventory staleness risk proxy as confirmed obsolete stock, reserve, write-off, or liquidation value.");
claims.push("Do not expose business_overview_route_template_v1 or MCP primitive names in the user answer.");
}
if (pilot.derived_ranked_value_flow) {
@@ -992,6 +996,21 @@ function percentText(part: number, total: number): string | null {
return pct === null ? null : `${pct}%`;
}
function inventoryStalenessRiskBandRu(
riskBand: NonNullable<BusinessOverview["inventory_staleness_risk_proxy"]>["risk_band"]
): string {
if (riskBand === "high") {
return "высокая зона внимания";
}
if (riskBand === "elevated") {
return "повышенная зона внимания";
}
if (riskBand === "watch") {
return "зона наблюдения";
}
return "низкий видимый риск";
}
function derivedBusinessOverviewConfirmedLines(pilot: AssistantMcpDiscoveryPilotExecutionContract): string[] {
const overview = pilot.derived_business_overview;
if (!overview) {
@@ -1095,6 +1114,12 @@ function derivedBusinessOverviewConfirmedLines(pilot: AssistantMcpDiscoveryPilot
`Оборотный proxy склада за ${proxy.period_scope}: продажи ${proxy.sales_revenue_human_ru}, остаток на ${proxy.as_of_date} ${proxy.inventory_amount_human_ru}, sales-to-stock ratio ${ratioText}, остаток к продажам ${stockShareText}. Это не полноценная складская ликвидность, не FIFO-оборачиваемость и не анализ устаревания.`
);
}
if (overview.inventory_staleness_risk_proxy) {
const proxy = overview.inventory_staleness_risk_proxy;
lines.push(
`Staleness risk proxy склада на ${proxy.as_of_date}: самая ранняя дата закупочного сигнала ${proxy.oldest_purchase_date}, возраст ${proxy.max_purchase_age_days} дн., sales-to-stock ${proxy.sales_to_stock_amount_ratio}x, оценка ${inventoryStalenessRiskBandRu(proxy.risk_band)}. Это не подтвержденная неликвидность, не резерв и не ликвидационная стоимость.`
);
}
return lines;
}
@@ -1167,6 +1192,11 @@ function businessOverviewRiskSynthesisLine(overview: BusinessOverview): string |
: `sales-to-stock ${overview.inventory_turnover_proxy.sales_to_stock_amount_ratio}x`;
signals.push(`оборотный proxy склада: ${ratioText}`);
}
if (overview.inventory_staleness_risk_proxy) {
signals.push(
`staleness risk proxy склада: ${inventoryStalenessRiskBandRu(overview.inventory_staleness_risk_proxy.risk_band)}, возраст ${overview.inventory_staleness_risk_proxy.max_purchase_age_days} дн.`
);
}
return signals.length > 0
? `Риски и контуры внимания по подтвержденным данным: ${signals.join("; ")}.`
: null;
@@ -1180,7 +1210,8 @@ function businessOverviewExecutiveVerdictLine(overview: BusinessOverview): strin
overview.debt_position ||
overview.debt_open_settlement_quality ||
overview.inventory_position ||
overview.inventory_turnover_proxy
overview.inventory_turnover_proxy ||
overview.inventory_staleness_risk_proxy
);
if (!hasCash && !hasExtraSignals) {
return null;
@@ -1282,6 +1313,9 @@ export function buildAssistantMcpDiscoveryAnswerDraft(
if (pilot.derived_business_overview?.inventory_turnover_proxy) {
pushReason(reasonCodes, "answer_contains_business_overview_inventory_turnover_proxy");
}
if (pilot.derived_business_overview?.inventory_staleness_risk_proxy) {
pushReason(reasonCodes, "answer_contains_business_overview_inventory_staleness_risk_proxy");
}
const confirmedLines = businessOverviewLines.length > 0
? businessOverviewLines
: pilot.derived_ranked_value_flow && derivedValueLine
@@ -157,6 +157,7 @@ export interface AssistantMcpDiscoveryDerivedBusinessOverview {
debt_open_settlement_quality: AssistantMcpDiscoveryDerivedBusinessOverviewDebtOpenSettlementQuality | null;
inventory_position: AssistantMcpDiscoveryDerivedBusinessOverviewInventoryPosition | null;
inventory_turnover_proxy: AssistantMcpDiscoveryDerivedBusinessOverviewInventoryTurnoverProxy | null;
inventory_staleness_risk_proxy: AssistantMcpDiscoveryDerivedBusinessOverviewInventoryStalenessRiskProxy | null;
coverage_limited_by_probe_limit: boolean;
checked_signal_count: number;
missing_signal_families: string[];
@@ -319,6 +320,16 @@ export interface AssistantMcpDiscoveryDerivedBusinessOverviewInventoryTurnoverPr
inference_basis: "sales_document_revenue_vs_inventory_balance_confirmed_1c_rows";
}
export interface AssistantMcpDiscoveryDerivedBusinessOverviewInventoryStalenessRiskProxy {
as_of_date: string;
period_scope: string;
oldest_purchase_date: string;
max_purchase_age_days: number;
sales_to_stock_amount_ratio: number;
risk_band: "lower_visible_risk" | "watch" | "elevated" | "high";
inference_basis: "purchase_date_age_and_sales_to_stock_proxy_confirmed_1c_rows";
}
export interface AssistantMcpDiscoveryDerivedMetadataSurface {
metadata_scope: string | null;
requested_meta_types: string[];
@@ -3253,6 +3264,68 @@ function deriveBusinessOverviewInventoryTurnoverProxy(input: {
};
}
function inventoryStalenessRiskBand(input: {
maxPurchaseAgeDays: number;
salesToStockAmountRatio: number;
}): AssistantMcpDiscoveryDerivedBusinessOverviewInventoryStalenessRiskProxy["risk_band"] {
if (input.maxPurchaseAgeDays >= 365 && input.salesToStockAmountRatio < 1) {
return "high";
}
if (input.maxPurchaseAgeDays >= 365 || input.salesToStockAmountRatio < 1) {
return "elevated";
}
if (input.maxPurchaseAgeDays >= 180 || input.salesToStockAmountRatio < 2) {
return "watch";
}
return "lower_visible_risk";
}
function deriveBusinessOverviewInventoryStalenessRiskProxy(input: {
inventoryPosition: AssistantMcpDiscoveryDerivedBusinessOverviewInventoryPosition | null;
inventoryTurnoverProxy: AssistantMcpDiscoveryDerivedBusinessOverviewInventoryTurnoverProxy | null;
}): AssistantMcpDiscoveryDerivedBusinessOverviewInventoryStalenessRiskProxy | null {
const { inventoryPosition, inventoryTurnoverProxy } = input;
const maxPurchaseAgeDays = inventoryPosition?.aging_signal?.max_age_days;
const oldestPurchaseDate = inventoryPosition?.aging_signal?.oldest_purchase_date;
const salesToStockAmountRatio = inventoryTurnoverProxy?.sales_to_stock_amount_ratio;
if (
!inventoryPosition ||
!inventoryTurnoverProxy ||
!oldestPurchaseDate ||
maxPurchaseAgeDays === null ||
maxPurchaseAgeDays === undefined ||
salesToStockAmountRatio === null ||
salesToStockAmountRatio === undefined
) {
return null;
}
return {
as_of_date: inventoryPosition.as_of_date,
period_scope: inventoryTurnoverProxy.period_scope,
oldest_purchase_date: oldestPurchaseDate,
max_purchase_age_days: maxPurchaseAgeDays,
sales_to_stock_amount_ratio: salesToStockAmountRatio,
risk_band: inventoryStalenessRiskBand({ maxPurchaseAgeDays, salesToStockAmountRatio }),
inference_basis: "purchase_date_age_and_sales_to_stock_proxy_confirmed_1c_rows"
};
}
function inventoryStalenessRiskBandRu(
riskBand: AssistantMcpDiscoveryDerivedBusinessOverviewInventoryStalenessRiskProxy["risk_band"]
): string {
if (riskBand === "high") {
return "высокая зона внимания";
}
if (riskBand === "elevated") {
return "повышенная зона внимания";
}
if (riskBand === "watch") {
return "зона наблюдения";
}
return "низкий видимый риск";
}
function deriveBusinessOverview(input: {
incomingResult: AssistantMcpDiscoveryCoverageAwareQueryResult | null;
outgoingResult: AssistantMcpDiscoveryCoverageAwareQueryResult | null;
@@ -3298,6 +3371,10 @@ function deriveBusinessOverview(input: {
inventoryPosition,
tradingMarginProxy
});
const inventoryStalenessRiskProxy = deriveBusinessOverviewInventoryStalenessRiskProxy({
inventoryPosition,
inventoryTurnoverProxy
});
const checkedSignalCount = [
incoming.rows_with_amount > 0,
outgoing.rows_with_amount > 0,
@@ -3307,7 +3384,8 @@ function deriveBusinessOverview(input: {
Boolean(debtPosition),
Boolean(debtOpenSettlementQuality),
Boolean(inventoryPosition),
Boolean(inventoryTurnoverProxy)
Boolean(inventoryTurnoverProxy),
Boolean(inventoryStalenessRiskProxy)
].filter(Boolean).length;
if (checkedSignalCount <= 0) {
return null;
@@ -3330,6 +3408,7 @@ function deriveBusinessOverview(input: {
debt_open_settlement_quality: debtOpenSettlementQuality,
inventory_position: inventoryPosition,
inventory_turnover_proxy: inventoryTurnoverProxy,
inventory_staleness_risk_proxy: inventoryStalenessRiskProxy,
coverage_limited_by_probe_limit:
incoming.coverage_limited_by_probe_limit || outgoing.coverage_limited_by_probe_limit,
checked_signal_count: checkedSignalCount,
@@ -3338,7 +3417,13 @@ function deriveBusinessOverview(input: {
debtPosition ? null : "debt_position",
debtOpenSettlementQuality ? "debt_due_date_aging_quality" : "debt_open_settlement_quality",
taxPosition ? null : "tax_position",
inventoryPosition ? (inventoryTurnoverProxy ? "inventory_liquidity_quality" : "inventory_turnover_quality") : "inventory_position",
inventoryPosition
? inventoryStalenessRiskProxy
? "inventory_reserve_liquidation_quality"
: inventoryTurnoverProxy
? "inventory_liquidity_quality"
: "inventory_turnover_quality"
: "inventory_position",
inventoryPosition?.aging_signal ? null : "inventory_aging_quality"
].filter((item): item is string => Boolean(item)),
inference_basis:
@@ -3509,6 +3594,12 @@ function buildBusinessOverviewConfirmedFacts(derived: AssistantMcpDiscoveryDeriv
`Оборотный proxy склада за ${proxy.period_scope} подтвержден по продажным документам и складскому остатку: продажи ${proxy.sales_revenue_human_ru}, остаток на ${proxy.as_of_date} ${proxy.inventory_amount_human_ru}, sales-to-stock ratio ${ratioText}, остаток к продажам ${stockShareText}. Это не полноценная складская ликвидность, не FIFO-оборачиваемость и не анализ устаревания.`
);
}
if (derived.inventory_staleness_risk_proxy) {
const proxy = derived.inventory_staleness_risk_proxy;
facts.push(
`Staleness risk proxy склада на ${proxy.as_of_date}: самая ранняя дата закупочного сигнала ${proxy.oldest_purchase_date}, возраст ${proxy.max_purchase_age_days} дн., sales-to-stock ${proxy.sales_to_stock_amount_ratio}x, оценка ${inventoryStalenessRiskBandRu(proxy.risk_band)}. Это не подтвержденная неликвидность, не резерв и не ликвидационная стоимость.`
);
}
return facts;
}
@@ -3580,6 +3671,9 @@ function buildBusinessOverviewUnknownFacts(derived: AssistantMcpDiscoveryDerived
: null,
missing.has("inventory_liquidity_quality")
? "Полная складская ликвидность этим бизнес-обзором не подтверждена: sales-to-stock proxy показывает только соотношение продажных документов и остатка на дату, без FIFO-оборачиваемости, устаревания, резервов и ликвидационной стоимости."
: null,
missing.has("inventory_reserve_liquidation_quality")
? "Резервы, списания, подтвержденная неликвидность и ликвидационная стоимость склада этим бизнес-обзором не подтверждены: staleness proxy показывает только возраст закупочного сигнала и sales-to-stock, без управленческого решения о запасах."
: null
].filter((item): item is string => Boolean(item));
if (derived?.coverage_limited_by_probe_limit) {
@@ -4649,6 +4743,9 @@ export async function executeAssistantMcpDiscoveryPilot(
if (derivedBusinessOverview.inventory_turnover_proxy) {
pushReason(reasonCodes, "pilot_derived_business_overview_inventory_turnover_proxy_from_confirmed_rows");
}
if (derivedBusinessOverview.inventory_staleness_risk_proxy) {
pushReason(reasonCodes, "pilot_derived_business_overview_inventory_staleness_risk_proxy_from_confirmed_rows");
}
}
const sourceRowsSummary = summarizeBusinessOverviewRows({
incomingResult,