Укрепить business overview и память по СВК

This commit is contained in:
2026-06-01 22:47:45 +03:00
parent ede15c6080
commit 987419fade
13 changed files with 172 additions and 29 deletions
@@ -3159,7 +3159,7 @@ function composeFactualReplyBody(intent, rows, options = {}) {
: `Коротко: подтвержденный НДС к уплате за налоговый период${organizationScopeLabel}${formatConfirmedMoney(vatToPay)}.`;
const lines = [
directVatLine,
"Расчет сделан по книгам продаж и покупок.",
"Расчет сделан по подтвержденным строкам книг продаж и покупок.",
"",
"Что вошло в расчет:",
...(organizationLabel ? [`- Организация: ${organizationLabel}.`] : []),
@@ -3169,6 +3169,7 @@ function composeFactualReplyBody(intent, rows, options = {}) {
`- НДС по книге покупок (вычеты): ${formatConfirmedMoney(purchaseVat)}.`,
`- Нетто НДС (книга продаж - книга покупок): ${formatConfirmedMoney(netVat)}.`
];
lines.push("", "Граница вывода: это подтвержденный баланс по найденным строкам книг продаж/покупок, но не полный налоговый вердикт и не сверка декларации; для финального вывода нужно отдельно проверить корректировки, применимость вычетов, закрытие периода и первичные документы.");
if (rows.length === 0) {
lines.push("", "За выбранный налоговый период не найдены строки книг продаж/покупок, поэтому подтвержденная сумма к уплате равна 0.");
}
@@ -327,9 +327,6 @@ function parseBusinessOverviewProofBundlesFromTextV2(value, counterpartyHint, to
return valueBundle || documentBundle ? { valueBundle, documentBundle } : null;
}
function findRecentBusinessOverviewProofBundles(input) {
if (!input.counterpartyHint) {
return null;
}
for (let index = input.sessionItems.length - 1; index >= 0; index -= 1) {
const item = toRecordObject(input.sessionItems[index]);
if (input.toNonEmptyString(item?.role) !== "assistant") {
@@ -344,7 +341,7 @@ function findRecentBusinessOverviewProofBundles(input) {
const documentBundle = toRecordObject(turnMeaningRef.previous_counterparty_document_bundle);
if (valueBundle || documentBundle) {
const bundleCounterparty = turnMeaningCounterpartyName(turnMeaningRef, valueBundle, documentBundle, input.toNonEmptyString);
if (sameEntityHint(input.counterpartyHint, bundleCounterparty)) {
if (!input.counterpartyHint || sameEntityHint(input.counterpartyHint, bundleCounterparty)) {
return { valueBundle, documentBundle };
}
}
@@ -356,7 +353,7 @@ function findRecentBusinessOverviewProofBundles(input) {
}
const parsedCounterparty = input.toNonEmptyString(parsedBundles.valueBundle?.counterparty) ??
input.toNonEmptyString(parsedBundles.documentBundle?.counterparty);
if (!sameEntityHint(input.counterpartyHint, parsedCounterparty)) {
if (input.counterpartyHint && !sameEntityHint(input.counterpartyHint, parsedCounterparty)) {
continue;
}
return parsedBundles;
@@ -381,7 +378,7 @@ function mergeBusinessOverviewProofBundlesFromNavigationState(input) {
const entities = toRecordObject(input.predecomposeContract?.entities);
const hasCurrentOrganizationSelection = Boolean(input.toNonEmptyString(entities?.organization));
const businessOverviewFollowup = isBusinessOverviewDiscoveryFollowup(input.followupContext, input.toNonEmptyString);
if (!hasComparisonScopeProofCue(input.userMessage)) {
if (!hasComparisonScopeProofCue(input.userMessage) && !hasCurrentOrganizationSelection) {
return input.followupContext;
}
if (!businessOverviewFollowup && !hasCurrentOrganizationSelection) {
@@ -416,10 +413,13 @@ function mergeBusinessOverviewProofBundlesFromNavigationState(input) {
};
}
function mergeBusinessOverviewProofBundlesFromSessionItems(input) {
if (!hasComparisonScopeProofCue(input.userMessage)) {
const businessOverviewFollowup = isBusinessOverviewDiscoveryFollowup(input.followupContext, input.toNonEmptyString);
const entities = toRecordObject(input.predecomposeContract?.entities);
const hasCurrentOrganizationSelection = Boolean(input.toNonEmptyString(entities?.organization));
if (!hasComparisonScopeProofCue(input.userMessage) && !businessOverviewFollowup && !hasCurrentOrganizationSelection) {
return input.followupContext;
}
if (!isBusinessOverviewDiscoveryFollowup(input.followupContext, input.toNonEmptyString)) {
if (!businessOverviewFollowup && !hasCurrentOrganizationSelection) {
return input.followupContext;
}
const currentValueBundle = toRecordObject(input.followupContext?.previous_discovery_bidirectional_value_flow);
@@ -438,8 +438,21 @@ function mergeBusinessOverviewProofBundlesFromSessionItems(input) {
if (!proofBundles) {
return input.followupContext;
}
const recoveredCounterparty = counterpartyHint ??
input.toNonEmptyString(proofBundles.valueBundle?.counterparty) ??
input.toNonEmptyString(proofBundles.documentBundle?.counterparty);
return {
...(input.followupContext ?? {}),
previous_intent: input.toNonEmptyString(input.followupContext?.previous_intent) ?? "business_overview",
target_intent: input.toNonEmptyString(input.followupContext?.target_intent) ?? "business_overview",
previous_discovery_pilot_scope: input.toNonEmptyString(input.followupContext?.previous_discovery_pilot_scope) ??
"business_overview_route_template_v1",
previous_discovery_loop_selected_chain_id: input.toNonEmptyString(input.followupContext?.previous_discovery_loop_selected_chain_id) ?? "business_overview",
previous_discovery_loop_asked_domain_family: input.toNonEmptyString(input.followupContext?.previous_discovery_loop_asked_domain_family) ?? "business_overview",
previous_discovery_loop_asked_action_family: input.toNonEmptyString(input.followupContext?.previous_discovery_loop_asked_action_family) ?? "broad_evaluation",
previous_discovery_loop_metadata_scope_hint: input.toNonEmptyString(input.followupContext?.previous_discovery_loop_metadata_scope_hint) ?? recoveredCounterparty ?? undefined,
previous_anchor_type: input.toNonEmptyString(input.followupContext?.previous_anchor_type) ?? (recoveredCounterparty ? "counterparty" : undefined),
previous_anchor_value: input.toNonEmptyString(input.followupContext?.previous_anchor_value) ?? recoveredCounterparty ?? undefined,
previous_discovery_bidirectional_value_flow: currentValueBundle ?? proofBundles.valueBundle ?? undefined,
previous_discovery_document_summary: currentDocumentBundle ?? proofBundles.documentBundle ?? undefined
};
@@ -620,6 +633,7 @@ async function buildAssistantAddressOrchestrationRuntime(input) {
const discoveryFollowupContextWithProofBundles = mergeBusinessOverviewProofBundlesFromSessionItems({
followupContext: discoveryFollowupContext,
userMessage: input.userMessage,
predecomposeContract,
sessionItems: input.sessionItems,
toNonEmptyString: input.toNonEmptyString
});
@@ -933,7 +933,7 @@ function buildCompactBusinessOverviewReply(entryPoint, draft) {
return joinBusinessReplyLines(lines);
}
if (plainOrganizationClarificationSelection && (incomingAmount || outgoingAmount || netAmount)) {
lines.push(`Коротко: по компании ${organizationScope} ${period} подтвержден company-level денежный срез: входящие ${incomingAmount ?? "0 руб."}, исходящие ${outgoingAmount ?? "0 руб."}, операционное нетто ${sentenceAmount(netAmount) ?? netAmount ?? "0 руб."}.`);
lines.push(`по компании ${organizationScope} ${period} подтвержден company-level денежный срез: входящие ${incomingAmount ?? "0 руб."}, исходящие ${outgoingAmount ?? "0 руб."}, операционное нетто ${sentenceAmount(netAmount) ?? netAmount ?? "0 руб."}.`);
if (previousCounterpartySummary) {
lines.push(previousCounterpartySummary.line);
}
@@ -1137,7 +1137,13 @@ function buildCompactBusinessOverviewReply(entryPoint, draft) {
(actionFamily === "broad_evaluation" || unsupportedFamily === "broad_business_evaluation")) {
const subject = organizationScope ?? "компания";
const periodWithoutPrefix = period.replace(/^за\s+/iu, "");
lines.push(`Коротко: по ограниченному проверенному 1С-срезу ${subject} выглядит как бизнес с крупными контрактными денежными потоками и заметной зависимостью от нескольких крупных контрагентов, а не как равномерный поток мелких продаж; это не аудиторское заключение и не подтвержденная чистая прибыль.`);
const executiveFacts = [
incomingAmount ? `входящие ${incomingAmount}` : null,
outgoingAmount ? `исходящие ${outgoingAmount}` : null,
netAmount ? `${netDirection} ${sentenceAmount(netAmount) ?? netAmount}` : null
].filter((value) => Boolean(value));
lines.push(`По подтвержденным строкам 1С ${subject} за ${periodWithoutPrefix}: ${executiveFacts.length > 0 ? executiveFacts.join(", ") : "денежные метрики не подтверждены"}; это ограниченный проверенный срез, не аудиторское заключение и не подтвержденная чистая прибыль.`);
lines.push("Интерпретация: по этому срезу видны крупные контрактные денежные потоки и заметная зависимость от нескольких крупных контрагентов, а не равномерный поток мелких продаж.");
lines.push("Что видно в ограниченном денежном срезе:");
if (incomingAmount) {
lines.push(`- входящие деньги за ${periodWithoutPrefix}: ${incomingAmount};`);
@@ -2088,10 +2088,13 @@ function buildAssistantMcpDiscoveryTurnInput(input) {
: undefined,
explicit_entity_candidates: businessOverviewSignal || shouldPreserveBusinessOverviewSeparateCounterparty ? [] : entityCandidates,
business_overview_separate_entity_candidates: businessOverviewSeparateEntityCandidates,
previous_counterparty_value_flow_bundle: businessOverviewSignal && followupSeed.previousBidirectionalValueFlow
previous_counterparty_value_flow_bundle: (businessOverviewSignal || shouldPreserveBusinessOverviewSeparateCounterparty) &&
followupSeed.previousBidirectionalValueFlow
? followupSeed.previousBidirectionalValueFlow
: undefined,
previous_counterparty_document_bundle: businessOverviewSignal && followupSeed.previousDocumentSummary ? followupSeed.previousDocumentSummary : undefined,
previous_counterparty_document_bundle: (businessOverviewSignal || shouldPreserveBusinessOverviewSeparateCounterparty) && followupSeed.previousDocumentSummary
? followupSeed.previousDocumentSummary
: undefined,
metadata_ambiguity_entity_sets: metadataAmbiguityLaneClarificationApplicable && followupSeed.metadataAmbiguityEntitySets.length > 0
? followupSeed.metadataAmbiguityEntitySets
: undefined,
@@ -409,7 +409,9 @@ function createAssistantTransitionPolicy(deps) {
if (!text) {
return null;
}
const match = text.match(/Отдельно\s+по\s+контрагенту\s+([^:\n]+):\s*подтверждено\s+получили\s+([^,\n]+?руб\.?),\s*заплатили\s+([^,\n]+?руб\.?),\s*расчетное\s+нетто\s+в\s+нашу\s+сторону\s+([^.\n]+?руб\.?)/iu);
const boundaryMatch = text.match(/Отдельно\s+по\s+контрагенту\s+([^:\n]+):\s*подтверждено\s+получили\s+([^,\n]+?руб\.?),\s*заплатили\s+([^,\n]+?руб\.?),\s*расчетное\s+нетто\s+в\s+нашу\s+сторону\s+([^.\n]+?руб\.?)/iu);
const directMatch = text.match(/по\s+контрагенту\s+([^.\n]+?)\s+в\s+проверенном\s+окне[\s\S]{0,160}?получили\s+([^,\n]+?руб\.?),\s*заплатили\s+([^;\n]+?руб\.?);\s*расчетное\s+нетто\s+в\s+нашу\s+сторону:?\s*([^.\n]+?руб\.?)/iu);
const match = boundaryMatch ?? directMatch;
if (!match?.[1] || !match?.[2] || !match?.[3] || !match?.[4]) {
return null;
}