Open-World: добавить профиль документов в бизнес-обзор
This commit is contained in:
+42
-3
@@ -399,6 +399,9 @@ function headlineFor(mode, pilot) {
|
||||
if (overview.activity_period) {
|
||||
families.push("активность");
|
||||
}
|
||||
if (overview.document_activity_profile) {
|
||||
families.push("профиль типов документов и разделов учета");
|
||||
}
|
||||
if (overview.tax_position) {
|
||||
families.push("НДС-позиция");
|
||||
}
|
||||
@@ -621,6 +624,7 @@ function buildMustNotClaim(pilot) {
|
||||
claims.push("Do not present business overview yearly operating-flow breakdown as profit, financial result, or a complete annual P&L.");
|
||||
claims.push("Do not present business overview trading-margin proxy as clean profit, accounting financial result, or exact cost-of-sales margin.");
|
||||
claims.push("Do not present business overview supplier concentration as vendor-risk audit, procurement quality, or full expense structure.");
|
||||
claims.push("Do not present business overview document/account-section activity profile as process quality, accounting correctness, or completeness of all 1C activity.");
|
||||
claims.push("Do not claim debt quality, VAT position, inventory health, or company health unless those contours were separately checked.");
|
||||
claims.push("Do not present a debt-position snapshot as debt aging, overdue debt, or credit-quality analysis.");
|
||||
claims.push("Do not present open-settlement concentration as contractual due-date aging or confirmed overdue debt.");
|
||||
@@ -977,6 +981,23 @@ function derivedBusinessOverviewConfirmedLines(pilot) {
|
||||
if (overview.activity_period) {
|
||||
lines.push(`Окно подтвержденной активности в 1С: ${overview.activity_period.first_activity_date} — ${overview.activity_period.latest_activity_date}; ориентировочно ${overview.activity_period.duration_human_ru}.`);
|
||||
}
|
||||
if (overview.document_activity_profile) {
|
||||
const profile = overview.document_activity_profile;
|
||||
const topDocument = profile.top_document_types[0];
|
||||
const topSection = profile.top_account_sections[0];
|
||||
const parts = [];
|
||||
if (topDocument) {
|
||||
const shareText = topDocument.share_pct === null ? "" : ` (${topDocument.share_pct}%)`;
|
||||
parts.push(`ведущий тип документов ${topDocument.document_type} — ${topDocument.count} документов${shareText}`);
|
||||
}
|
||||
if (topSection) {
|
||||
const shareText = topSection.share_pct === null ? "" : ` (${topSection.share_pct}%)`;
|
||||
parts.push(`ведущий раздел учета ${topSection.account_section} — ${topSection.operation_count} операций${shareText}`);
|
||||
}
|
||||
if (parts.length > 0) {
|
||||
lines.push(`Профиль операционной активности${organization}${period}: ${parts.join("; ")}. Это activity mix по найденным строкам 1С, а не аудит качества учета или полноты процессов.`);
|
||||
}
|
||||
}
|
||||
if (overview.tax_position) {
|
||||
const taxDirection = overview.tax_position.net_vat_direction === "vat_to_pay"
|
||||
? "к уплате"
|
||||
@@ -1138,6 +1159,17 @@ function businessOverviewRiskSynthesisLine(overview) {
|
||||
if (overview.debt_staleness_risk_proxy) {
|
||||
signals.push(`staleness risk proxy открытых расчетов: ${debtStalenessRiskBandRu(overview.debt_staleness_risk_proxy.risk_band)}, возраст ${overview.debt_staleness_risk_proxy.max_contract_age_days} дн., концентрация старейшего крупного договора ${overview.debt_staleness_risk_proxy.top_contract_share_pct}%`);
|
||||
}
|
||||
if (overview.document_activity_profile) {
|
||||
const topDocument = overview.document_activity_profile.top_document_types[0];
|
||||
const topSection = overview.document_activity_profile.top_account_sections[0];
|
||||
const parts = [
|
||||
topDocument ? `ведущий тип документов ${topDocument.document_type}` : null,
|
||||
topSection ? `ведущий раздел учета ${topSection.account_section}` : null
|
||||
].filter((item) => Boolean(item));
|
||||
if (parts.length > 0) {
|
||||
signals.push(`операционный activity mix: ${parts.join(", ")}`);
|
||||
}
|
||||
}
|
||||
if (overview.inventory_position) {
|
||||
signals.push(`складской остаток на дату ${overview.inventory_position.total_amount_human_ru}`);
|
||||
if (overview.inventory_position.aging_signal?.max_age_days !== null && overview.inventory_position.aging_signal?.max_age_days !== undefined) {
|
||||
@@ -1159,7 +1191,7 @@ function businessOverviewRiskSynthesisLine(overview) {
|
||||
}
|
||||
function businessOverviewExecutiveVerdictLine(overview) {
|
||||
const hasCash = overview.incoming_customer_revenue.rows_with_amount > 0 || overview.outgoing_supplier_payout.rows_with_amount > 0;
|
||||
const hasExtraSignals = Boolean(overview.tax_position ||
|
||||
const hasTaxDebtInventorySignals = Boolean(overview.tax_position ||
|
||||
overview.trading_margin_proxy ||
|
||||
overview.debt_position ||
|
||||
overview.debt_open_settlement_quality ||
|
||||
@@ -1167,6 +1199,8 @@ function businessOverviewExecutiveVerdictLine(overview) {
|
||||
overview.inventory_position ||
|
||||
overview.inventory_turnover_proxy ||
|
||||
overview.inventory_staleness_risk_proxy);
|
||||
const hasDocumentActivitySignal = Boolean(overview.document_activity_profile);
|
||||
const hasExtraSignals = hasTaxDebtInventorySignals || hasDocumentActivitySignal;
|
||||
if (!hasCash && !hasExtraSignals) {
|
||||
return null;
|
||||
}
|
||||
@@ -1175,9 +1209,11 @@ function businessOverviewExecutiveVerdictLine(overview) {
|
||||
: overview.net_direction === "net_outgoing"
|
||||
? "операционно исходящий поток сильнее входящего, это зона внимания к расходам/закупкам"
|
||||
: "операционный поток выглядит сбалансированным";
|
||||
const evidenceTone = hasExtraSignals
|
||||
const evidenceTone = hasTaxDebtInventorySignals
|
||||
? "часть налоговых, долговых или складских контуров уже отдельно проверена"
|
||||
: "налоги, долги и склад еще не дают проверенного управленческого контекста";
|
||||
: hasDocumentActivitySignal
|
||||
? "операционный activity mix по типам документов и разделам учета уже отдельно проверен"
|
||||
: "налоги, долги и склад еще не дают проверенного управленческого контекста";
|
||||
return `Сводный LLM-аудит по подтвержденному: ${cashTone}; ${evidenceTone}. Это полезный управленческий срез по найденным строкам 1С, но не финальный вывод о прибыльности, марже или здоровье компании.`;
|
||||
}
|
||||
function derivedBusinessOverviewInferenceLines(pilot) {
|
||||
@@ -1251,6 +1287,9 @@ function buildAssistantMcpDiscoveryAnswerDraft(pilot) {
|
||||
if (pilot.derived_business_overview?.yearly_breakdown?.length) {
|
||||
pushReason(reasonCodes, "answer_contains_business_overview_yearly_operating_breakdown");
|
||||
}
|
||||
if (pilot.derived_business_overview?.document_activity_profile) {
|
||||
pushReason(reasonCodes, "answer_contains_business_overview_document_activity_profile");
|
||||
}
|
||||
if (pilot.derived_business_overview?.debt_position) {
|
||||
pushReason(reasonCodes, "answer_contains_business_overview_debt_position");
|
||||
}
|
||||
|
||||
+145
-9
@@ -160,6 +160,17 @@ function buildValueFlowFilters(planner) {
|
||||
sort: "period_asc"
|
||||
};
|
||||
}
|
||||
function buildBusinessOverviewDocumentActivityFilters(planner) {
|
||||
const meaning = planner.discovery_plan.turn_meaning_ref;
|
||||
const organization = toNonEmptyString(meaning?.explicit_organization_scope);
|
||||
const dateScope = toNonEmptyString(meaning?.explicit_date_scope);
|
||||
return {
|
||||
...dateScopeToFilters(dateScope),
|
||||
...(organization ? { organization } : {}),
|
||||
limit: planner.discovery_plan.execution_budget.max_rows_per_probe,
|
||||
sort: "period_asc"
|
||||
};
|
||||
}
|
||||
function buildBusinessOverviewTaxFilters(planner) {
|
||||
const meaning = planner.discovery_plan.turn_meaning_ref;
|
||||
const organization = toNonEmptyString(meaning?.explicit_organization_scope);
|
||||
@@ -1836,6 +1847,75 @@ function deriveBusinessOverviewYearlyBreakdown(input) {
|
||||
};
|
||||
});
|
||||
}
|
||||
function normalizeBusinessOverviewActivityMarker(row) {
|
||||
const marker = toNonEmptyString(rowDocumentValue(row));
|
||||
return marker ? marker.trim().toUpperCase() : null;
|
||||
}
|
||||
function normalizeBusinessOverviewAccountSection(value) {
|
||||
const normalized = String(value ?? "").replace(/\s+/g, "").trim();
|
||||
if (!normalized) {
|
||||
return null;
|
||||
}
|
||||
const sectionMatch = normalized.match(/^(\d{2})(?:[.\-_/]|$)/);
|
||||
return sectionMatch?.[1] ?? normalized;
|
||||
}
|
||||
function deriveBusinessOverviewDocumentActivityProfile(result, periodScope) {
|
||||
if (!result || result.error || result.matched_rows <= 0) {
|
||||
return null;
|
||||
}
|
||||
const documentTypeBuckets = new Map();
|
||||
const accountSectionBuckets = new Map();
|
||||
for (const row of result.rows) {
|
||||
const marker = normalizeBusinessOverviewActivityMarker(row);
|
||||
const count = rowAmountValue(row);
|
||||
if (!marker || count === null || count <= 0) {
|
||||
continue;
|
||||
}
|
||||
if (marker === "DOC_TYPE_DOCS") {
|
||||
const documentType = rowDebitAccountValue(row) ?? rowAccountValue(row);
|
||||
if (documentType) {
|
||||
documentTypeBuckets.set(documentType, (documentTypeBuckets.get(documentType) ?? 0) + count);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (marker === "SECTION_DT_OPS" || marker === "SECTION_KT_OPS") {
|
||||
const section = normalizeBusinessOverviewAccountSection(rowDebitAccountValue(row) ?? rowAccountValue(row));
|
||||
if (section) {
|
||||
accountSectionBuckets.set(section, (accountSectionBuckets.get(section) ?? 0) + count);
|
||||
}
|
||||
}
|
||||
}
|
||||
const totalDocumentTypeCount = Array.from(documentTypeBuckets.values()).reduce((sum, count) => sum + count, 0);
|
||||
const totalAccountSectionOperations = Array.from(accountSectionBuckets.values()).reduce((sum, count) => sum + count, 0);
|
||||
const topDocumentTypes = Array.from(documentTypeBuckets.entries())
|
||||
.map(([documentType, count]) => ({
|
||||
document_type: documentType,
|
||||
count,
|
||||
share_pct: percentageOfTotal(count, totalDocumentTypeCount)
|
||||
}))
|
||||
.sort((left, right) => right.count - left.count || left.document_type.localeCompare(right.document_type, "ru"))
|
||||
.slice(0, 5);
|
||||
const topAccountSections = Array.from(accountSectionBuckets.entries())
|
||||
.map(([accountSection, operationCount]) => ({
|
||||
account_section: accountSection,
|
||||
operation_count: operationCount,
|
||||
share_pct: percentageOfTotal(operationCount, totalAccountSectionOperations)
|
||||
}))
|
||||
.sort((left, right) => right.operation_count - left.operation_count || left.account_section.localeCompare(right.account_section, "ru"))
|
||||
.slice(0, 5);
|
||||
if (topDocumentTypes.length <= 0 && topAccountSections.length <= 0) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
period_scope: periodScope,
|
||||
rows_matched: result.matched_rows,
|
||||
total_document_type_count: totalDocumentTypeCount,
|
||||
total_account_section_operations: totalAccountSectionOperations,
|
||||
top_document_types: topDocumentTypes,
|
||||
top_account_sections: topAccountSections,
|
||||
inference_basis: "document_type_and_account_section_profile_confirmed_1c_rows"
|
||||
};
|
||||
}
|
||||
function deriveValueFlow(result, counterparty, periodScope, direction, aggregationAxis) {
|
||||
if (!result || result.error || result.matched_rows <= 0) {
|
||||
return null;
|
||||
@@ -2633,6 +2713,7 @@ function deriveBusinessOverview(input) {
|
||||
openContractsResult: input.openContractsResult,
|
||||
debtAsOfDate: input.debtAsOfDate
|
||||
});
|
||||
const documentActivityProfile = deriveBusinessOverviewDocumentActivityProfile(input.documentActivityProfileResult, input.periodScope);
|
||||
const debtStalenessRiskProxy = deriveBusinessOverviewDebtStalenessRiskProxy(debtOpenSettlementQuality);
|
||||
const inventoryPosition = deriveBusinessOverviewInventoryPosition({
|
||||
inventoryOnHandResult: input.inventoryOnHandResult,
|
||||
@@ -2656,6 +2737,7 @@ function deriveBusinessOverview(input) {
|
||||
Boolean(debtPosition),
|
||||
Boolean(debtOpenSettlementQuality),
|
||||
Boolean(debtStalenessRiskProxy),
|
||||
Boolean(documentActivityProfile),
|
||||
Boolean(inventoryPosition),
|
||||
Boolean(inventoryTurnoverProxy),
|
||||
Boolean(inventoryStalenessRiskProxy)
|
||||
@@ -2684,6 +2766,7 @@ function deriveBusinessOverview(input) {
|
||||
inventory_position: inventoryPosition,
|
||||
inventory_turnover_proxy: inventoryTurnoverProxy,
|
||||
inventory_staleness_risk_proxy: inventoryStalenessRiskProxy,
|
||||
document_activity_profile: documentActivityProfile,
|
||||
coverage_limited_by_probe_limit: incoming.coverage_limited_by_probe_limit || outgoing.coverage_limited_by_probe_limit,
|
||||
checked_signal_count: checkedSignalCount,
|
||||
missing_signal_families: [
|
||||
@@ -2700,17 +2783,19 @@ function deriveBusinessOverview(input) {
|
||||
: "inventory_position",
|
||||
inventoryPosition?.aging_signal ? null : "inventory_aging_quality"
|
||||
].filter((item) => Boolean(item)),
|
||||
inference_basis: inventoryPosition
|
||||
inference_basis: documentActivityProfile
|
||||
? "business_overview_from_confirmed_1c_multi_family_rows"
|
||||
: debtOpenSettlementQuality
|
||||
: inventoryPosition
|
||||
? "business_overview_from_confirmed_1c_multi_family_rows"
|
||||
: taxPosition && debtPosition
|
||||
? "business_overview_from_confirmed_1c_money_activity_tax_and_debt_rows"
|
||||
: taxPosition
|
||||
? "business_overview_from_confirmed_1c_money_activity_and_tax_rows"
|
||||
: debtPosition
|
||||
? "business_overview_from_confirmed_1c_money_activity_and_debt_rows"
|
||||
: "business_overview_from_confirmed_1c_money_and_activity_rows"
|
||||
: debtOpenSettlementQuality
|
||||
? "business_overview_from_confirmed_1c_multi_family_rows"
|
||||
: taxPosition && debtPosition
|
||||
? "business_overview_from_confirmed_1c_money_activity_tax_and_debt_rows"
|
||||
: taxPosition
|
||||
? "business_overview_from_confirmed_1c_money_activity_and_tax_rows"
|
||||
: debtPosition
|
||||
? "business_overview_from_confirmed_1c_money_activity_and_debt_rows"
|
||||
: "business_overview_from_confirmed_1c_money_and_activity_rows"
|
||||
};
|
||||
}
|
||||
function summarizeBusinessOverviewRows(input) {
|
||||
@@ -2739,6 +2824,9 @@ function summarizeBusinessOverviewRows(input) {
|
||||
if (input.openContractsResult && !input.openContractsResult.error) {
|
||||
parts.push(`${input.openContractsResult.fetched_rows} open-contract rows fetched, ${input.openContractsResult.matched_rows} matched`);
|
||||
}
|
||||
if (input.documentActivityProfileResult && !input.documentActivityProfileResult.error) {
|
||||
parts.push(`${input.documentActivityProfileResult.fetched_rows} document/account-section profile rows fetched, ${input.documentActivityProfileResult.matched_rows} matched`);
|
||||
}
|
||||
if (input.inventoryOnHandResult && !input.inventoryOnHandResult.error) {
|
||||
parts.push(`${input.inventoryOnHandResult.fetched_rows} inventory on-hand rows fetched, ${input.inventoryOnHandResult.matched_rows} matched`);
|
||||
}
|
||||
@@ -2774,6 +2862,23 @@ function buildBusinessOverviewConfirmedFacts(derived) {
|
||||
if (derived.activity_period) {
|
||||
facts.push(`Подтвержденное окно активности в 1С: ${derived.activity_period.first_activity_date} — ${derived.activity_period.latest_activity_date}.`);
|
||||
}
|
||||
if (derived.document_activity_profile) {
|
||||
const profile = derived.document_activity_profile;
|
||||
const topDocument = profile.top_document_types[0];
|
||||
const topSection = profile.top_account_sections[0];
|
||||
const parts = [];
|
||||
if (topDocument) {
|
||||
const shareText = topDocument.share_pct === null ? "" : ` (${topDocument.share_pct}%)`;
|
||||
parts.push(`ведущий тип документов ${topDocument.document_type} — ${topDocument.count} документов${shareText}`);
|
||||
}
|
||||
if (topSection) {
|
||||
const shareText = topSection.share_pct === null ? "" : ` (${topSection.share_pct}%)`;
|
||||
parts.push(`ведущий раздел учета ${topSection.account_section} — ${topSection.operation_count} операций${shareText}`);
|
||||
}
|
||||
if (parts.length > 0) {
|
||||
facts.push(`Профиль операционной активности${organization}${period} подтвержден по типам документов и разделам учета 1С: ${parts.join("; ")}. Это activity mix, а не аудит качества учета или полноты бизнес-процессов.`);
|
||||
}
|
||||
}
|
||||
if (derived.tax_position) {
|
||||
const taxDirection = derived.tax_position.net_vat_direction === "vat_to_pay"
|
||||
? "к уплате"
|
||||
@@ -3537,10 +3642,12 @@ async function executeAssistantMcpDiscoveryPilot(planner, deps = DEFAULT_DEPS) {
|
||||
let receivablesResult = null;
|
||||
let payablesResult = null;
|
||||
let openContractsResult = null;
|
||||
let documentActivityProfileResult = null;
|
||||
let inventoryOnHandResult = null;
|
||||
let inventoryAgingResult = null;
|
||||
const valueFilters = buildValueFlowFilters(planner);
|
||||
const lifecycleFilters = buildLifecycleFilters(planner);
|
||||
const documentActivityFilters = buildBusinessOverviewDocumentActivityFilters(planner);
|
||||
const taxFilters = buildBusinessOverviewTaxFilters(planner);
|
||||
const tradingMarginFilters = buildBusinessOverviewTradingMarginFilters(planner);
|
||||
const debtFilters = buildBusinessOverviewDebtFilters(planner);
|
||||
@@ -3550,6 +3657,7 @@ async function executeAssistantMcpDiscoveryPilot(planner, deps = DEFAULT_DEPS) {
|
||||
const incomingSelection = (0, addressRecipeCatalog_1.selectAddressRecipe)("customer_revenue_and_payments", valueFilters);
|
||||
const outgoingSelection = (0, addressRecipeCatalog_1.selectAddressRecipe)("supplier_payouts_profile", valueFilters);
|
||||
const lifecycleSelection = (0, addressRecipeCatalog_1.selectAddressRecipe)("counterparty_activity_lifecycle", lifecycleFilters);
|
||||
const documentActivitySelection = (0, addressRecipeCatalog_1.selectAddressRecipe)("document_type_and_account_section_profile", documentActivityFilters);
|
||||
const taxSelection = taxFilters
|
||||
? (0, addressRecipeCatalog_1.selectAddressRecipe)("vat_liability_confirmed_for_tax_period", taxFilters)
|
||||
: null;
|
||||
@@ -3601,6 +3709,13 @@ async function executeAssistantMcpDiscoveryPilot(planner, deps = DEFAULT_DEPS) {
|
||||
};
|
||||
}
|
||||
pushReason(reasonCodes, "pilot_business_overview_recipes_selected");
|
||||
if (documentActivitySelection.selected_recipe) {
|
||||
pushReason(reasonCodes, "pilot_business_overview_document_activity_profile_recipe_selected");
|
||||
}
|
||||
else {
|
||||
pushReason(reasonCodes, "pilot_business_overview_document_activity_profile_recipe_not_available");
|
||||
pushUnique(queryLimitations, "Business overview document/account-section profile requires an executable document-section profile recipe");
|
||||
}
|
||||
if (taxSelection?.selected_recipe) {
|
||||
pushReason(reasonCodes, "pilot_business_overview_tax_recipe_selected");
|
||||
}
|
||||
@@ -3824,6 +3939,15 @@ async function executeAssistantMcpDiscoveryPilot(planner, deps = DEFAULT_DEPS) {
|
||||
});
|
||||
probeResults.push(queryResultToProbeResult(step.primitive_id, tradingMarginResult));
|
||||
}
|
||||
if (documentActivitySelection.selected_recipe) {
|
||||
const documentActivityPlan = (0, addressRecipeCatalog_1.buildAddressRecipePlan)(documentActivitySelection.selected_recipe, documentActivityFilters);
|
||||
documentActivityProfileResult = await runtimeDeps.executeAddressMcpQuery({
|
||||
query: documentActivityPlan.query,
|
||||
limit: documentActivityPlan.limit,
|
||||
account_scope: documentActivityPlan.account_scope
|
||||
});
|
||||
probeResults.push(queryResultToProbeResult(step.primitive_id, documentActivityProfileResult));
|
||||
}
|
||||
if (lifecycleResult.error) {
|
||||
pushUnique(queryLimitations, lifecycleResult.error);
|
||||
pushReason(reasonCodes, "pilot_business_overview_query_documents_mcp_error");
|
||||
@@ -3838,6 +3962,13 @@ async function executeAssistantMcpDiscoveryPilot(planner, deps = DEFAULT_DEPS) {
|
||||
else if (tradingMarginResult) {
|
||||
pushReason(reasonCodes, "pilot_business_overview_trading_margin_query_mcp_executed");
|
||||
}
|
||||
if (documentActivityProfileResult?.error) {
|
||||
pushUnique(queryLimitations, documentActivityProfileResult.error);
|
||||
pushReason(reasonCodes, "pilot_business_overview_document_activity_profile_query_mcp_error");
|
||||
}
|
||||
else if (documentActivityProfileResult) {
|
||||
pushReason(reasonCodes, "pilot_business_overview_document_activity_profile_query_mcp_executed");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
skippedPrimitives.push(step.primitive_id);
|
||||
@@ -3852,6 +3983,7 @@ async function executeAssistantMcpDiscoveryPilot(planner, deps = DEFAULT_DEPS) {
|
||||
receivablesResult,
|
||||
payablesResult,
|
||||
openContractsResult,
|
||||
documentActivityProfileResult,
|
||||
debtAsOfDate,
|
||||
inventoryOnHandResult,
|
||||
inventoryAgingResult,
|
||||
@@ -3873,6 +4005,9 @@ async function executeAssistantMcpDiscoveryPilot(planner, deps = DEFAULT_DEPS) {
|
||||
if (derivedBusinessOverview.activity_period) {
|
||||
pushReason(reasonCodes, "pilot_derived_business_overview_activity_window_from_confirmed_rows");
|
||||
}
|
||||
if (derivedBusinessOverview.document_activity_profile) {
|
||||
pushReason(reasonCodes, "pilot_derived_business_overview_document_activity_profile_from_confirmed_rows");
|
||||
}
|
||||
if (derivedBusinessOverview.tax_position) {
|
||||
pushReason(reasonCodes, "pilot_derived_business_overview_tax_position_from_confirmed_rows");
|
||||
}
|
||||
@@ -3910,6 +4045,7 @@ async function executeAssistantMcpDiscoveryPilot(planner, deps = DEFAULT_DEPS) {
|
||||
receivablesResult,
|
||||
payablesResult,
|
||||
openContractsResult,
|
||||
documentActivityProfileResult,
|
||||
inventoryOnHandResult,
|
||||
inventoryAgingResult
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user