Open-World: расширить бизнес-обзор факт-семействами
This commit is contained in:
@@ -158,6 +158,10 @@ function isValueFlowPilot(pilot: AssistantMcpDiscoveryPilotExecutionContract): b
|
||||
);
|
||||
}
|
||||
|
||||
function isBusinessOverviewPilot(pilot: AssistantMcpDiscoveryPilotExecutionContract): boolean {
|
||||
return pilot.pilot_scope === "business_overview_route_template_v1";
|
||||
}
|
||||
|
||||
function isDocumentPilot(pilot: AssistantMcpDiscoveryPilotExecutionContract): boolean {
|
||||
return pilot.pilot_scope === "counterparty_document_evidence_query_documents_v1";
|
||||
}
|
||||
@@ -431,6 +435,44 @@ function headlineFor(mode: AssistantMcpDiscoveryAnswerMode, pilot: AssistantMcpD
|
||||
}
|
||||
return "Инвентарный route-template уже выбран, но live-исполнение этого generic MCP контура еще не подключено; складской/товарный факт не подтвержден.";
|
||||
}
|
||||
if (isBusinessOverviewPilot(pilot) && pilot.derived_business_overview && mode === "confirmed_with_bounded_inference") {
|
||||
const overview = pilot.derived_business_overview;
|
||||
const families: string[] = [];
|
||||
if (
|
||||
overview.incoming_customer_revenue.rows_with_amount > 0 ||
|
||||
overview.outgoing_supplier_payout.rows_with_amount > 0
|
||||
) {
|
||||
families.push("денежный поток");
|
||||
}
|
||||
if (overview.activity_period) {
|
||||
families.push("активность");
|
||||
}
|
||||
if (overview.tax_position) {
|
||||
families.push("НДС-позиция");
|
||||
}
|
||||
if (overview.debt_position) {
|
||||
families.push("долговой срез на дату");
|
||||
}
|
||||
if (overview.debt_open_settlement_quality) {
|
||||
families.push("качество открытых расчетов");
|
||||
}
|
||||
if (overview.inventory_position) {
|
||||
families.push("складской срез на дату");
|
||||
}
|
||||
const unknownFamilies = ["прибыль/маржа"];
|
||||
if (!overview.tax_position) {
|
||||
unknownFamilies.push("НДС");
|
||||
}
|
||||
if (!overview.debt_position) {
|
||||
unknownFamilies.push("долговой срез");
|
||||
}
|
||||
unknownFamilies.push(overview.debt_open_settlement_quality ? "due-date просрочка" : "качество открытых расчетов");
|
||||
unknownFamilies.push(overview.inventory_position ? "полноценная складская ликвидность" : "склад");
|
||||
return `По данным 1С собран ограниченный бизнес-обзор: ${families.join(", ")} подтверждены найденными строками; ${unknownFamilies.join(", ")} остаются отдельными непроверенными областями.`;
|
||||
}
|
||||
if (isBusinessOverviewPilot(pilot) && mode === "checked_sources_only") {
|
||||
return "Бизнес-обзор был запущен, но подтвержденные денежные или activity-сигналы в найденных строках не получены.";
|
||||
}
|
||||
if (isEntityResolutionPilot(pilot) && mode === "needs_clarification") {
|
||||
return "По каталогу 1С нашлось несколько похожих контрагентов, и без уточнения нельзя честно выбрать правильную сущность.";
|
||||
}
|
||||
@@ -574,6 +616,9 @@ function nextStepFor(mode: AssistantMcpDiscoveryAnswerMode, pilot: AssistantMcpD
|
||||
}
|
||||
return "Следующий шаг - связать inventory route-template с exact inventory runtime и затем проверить live-прогоном.";
|
||||
}
|
||||
if (mode === "confirmed_with_bounded_inference" && isBusinessOverviewPilot(pilot)) {
|
||||
return "Если нужен уже управленческий вывод, следующим шагом стоит отдельно проверить прибыль/маржу, долги, НДС и складскую ликвидность, а затем собрать полный бизнес-аудит.";
|
||||
}
|
||||
if (mode === "confirmed_with_bounded_inference" && pilot.derived_metadata_surface) {
|
||||
const surface = pilot.derived_metadata_surface;
|
||||
if (surface.ambiguity_detected && surface.ambiguity_entity_sets.length > 0) {
|
||||
@@ -606,6 +651,14 @@ function buildMustNotClaim(pilot: AssistantMcpDiscoveryPilotExecutionContract):
|
||||
claims.push("Do not claim full all-time turnover unless the checked period and coverage prove it.");
|
||||
claims.push("Do not present a derived sum as a legal/accounting final total outside the checked 1C rows.");
|
||||
}
|
||||
if (isBusinessOverviewPilot(pilot)) {
|
||||
claims.push("Do not present business overview cash-flow spread as profit or margin.");
|
||||
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.");
|
||||
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 expose business_overview_route_template_v1 or MCP primitive names in the user answer.");
|
||||
}
|
||||
if (pilot.derived_ranked_value_flow) {
|
||||
claims.push("Do not present a bounded ranking as a complete all-time ranking outside the checked period and organization.");
|
||||
claims.push("Do not imply the top-ranked counterparty is globally final when probe-limit or scope boundaries still exist.");
|
||||
@@ -899,6 +952,119 @@ function derivedBidirectionalValueFlowMonthlyLines(pilot: AssistantMcpDiscoveryP
|
||||
);
|
||||
}
|
||||
|
||||
function businessOverviewNetDirectionRu(direction: "net_incoming" | "net_outgoing" | "balanced"): string {
|
||||
if (direction === "net_incoming") {
|
||||
return "операционный денежный поток в проверенном срезе больше входящий, чем исходящий";
|
||||
}
|
||||
if (direction === "net_outgoing") {
|
||||
return "операционный денежный поток в проверенном срезе больше исходящий, чем входящий";
|
||||
}
|
||||
return "входящий и исходящий денежный поток в проверенном срезе примерно сбалансированы";
|
||||
}
|
||||
|
||||
function derivedBusinessOverviewConfirmedLines(pilot: AssistantMcpDiscoveryPilotExecutionContract): string[] {
|
||||
const overview = pilot.derived_business_overview;
|
||||
if (!overview) {
|
||||
return [];
|
||||
}
|
||||
const organization = overview.organization_scope ? ` по организации ${overview.organization_scope}` : "";
|
||||
const period = overview.period_scope ? ` за ${overview.period_scope}` : " за все доступное проверенное окно";
|
||||
const lines: string[] = [];
|
||||
if (overview.incoming_customer_revenue.rows_with_amount > 0) {
|
||||
lines.push(
|
||||
`Входящие поступления${organization}${period}: ${overview.incoming_customer_revenue.total_amount_human_ru} по ${overview.incoming_customer_revenue.rows_with_amount} строкам с суммой.`
|
||||
);
|
||||
}
|
||||
if (overview.outgoing_supplier_payout.rows_with_amount > 0) {
|
||||
lines.push(
|
||||
`Исходящие платежи/списания${organization}${period}: ${overview.outgoing_supplier_payout.total_amount_human_ru} по ${overview.outgoing_supplier_payout.rows_with_amount} строкам с суммой.`
|
||||
);
|
||||
}
|
||||
const leader = overview.top_customers[0];
|
||||
if (leader) {
|
||||
lines.push(`Самый крупный подтвержденный клиент в проверенном срезе: ${leader.axis_value} — ${leader.total_amount_human_ru}.`);
|
||||
}
|
||||
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.tax_position) {
|
||||
const taxDirection =
|
||||
overview.tax_position.net_vat_direction === "vat_to_pay"
|
||||
? "к уплате"
|
||||
: overview.tax_position.net_vat_direction === "vat_to_recover_or_offset"
|
||||
? "к вычету/зачету"
|
||||
: "сбалансирован";
|
||||
lines.push(
|
||||
`НДС-позиция за ${overview.tax_position.period_scope}: книга продаж ${overview.tax_position.sales_vat_amount_human_ru}, книга покупок/вычеты ${overview.tax_position.purchase_vat_amount_human_ru}, нетто ${taxDirection} ${overview.tax_position.net_vat_amount_human_ru}.`
|
||||
);
|
||||
}
|
||||
if (overview.debt_position) {
|
||||
const debtDirection =
|
||||
overview.debt_position.net_debt_position_direction === "net_receivable"
|
||||
? "в пользу дебиторки"
|
||||
: overview.debt_position.net_debt_position_direction === "net_payable"
|
||||
? "в сторону кредиторки"
|
||||
: "сбалансировано";
|
||||
lines.push(
|
||||
`Долговой срез на ${overview.debt_position.as_of_date}: дебиторка ${overview.debt_position.receivables.total_amount_human_ru}, кредиторка ${overview.debt_position.payables.total_amount_human_ru}, нетто ${debtDirection} ${overview.debt_position.net_debt_position_amount_human_ru}.`
|
||||
);
|
||||
}
|
||||
if (overview.debt_open_settlement_quality) {
|
||||
const quality = overview.debt_open_settlement_quality;
|
||||
const topContract = quality.top_contracts[0];
|
||||
const topContractText = topContract
|
||||
? ` Крупнейший открытый договор: ${topContract.contract}${topContract.counterparty ? ` / ${topContract.counterparty}` : ""} — ${topContract.total_amount_human_ru}${topContract.share_of_gross_open_amount_pct === null ? "" : ` (${topContract.share_of_gross_open_amount_pct}%)`}.`
|
||||
: "";
|
||||
lines.push(
|
||||
`Качество открытых расчетов на ${quality.as_of_date}: брутто открытых договорных остатков ${quality.gross_open_amount_human_ru}, договоров ${quality.unique_contracts}, контрагентов ${quality.unique_counterparties}.${topContractText}`
|
||||
);
|
||||
}
|
||||
if (overview.inventory_position) {
|
||||
const leader = overview.inventory_position.top_items[0];
|
||||
const leaderText = leader
|
||||
? ` Крупнейшая подтвержденная позиция: ${leader.item} — ${leader.total_amount_human_ru}.`
|
||||
: "";
|
||||
lines.push(
|
||||
`Складской срез на ${overview.inventory_position.as_of_date}: остаток ${overview.inventory_position.total_amount_human_ru} по ${overview.inventory_position.rows_with_amount} строкам с суммой и ${overview.inventory_position.rows_with_quantity} строкам с количеством.${leaderText}`
|
||||
);
|
||||
if (overview.inventory_position.aging_signal?.oldest_purchase_date) {
|
||||
const ageText = overview.inventory_position.aging_signal.max_age_days === null
|
||||
? ""
|
||||
: `, максимальный возраст сигнала ${overview.inventory_position.aging_signal.max_age_days} дн.`;
|
||||
lines.push(
|
||||
`Возрастной сигнал склада: самая ранняя найденная дата закупки ${overview.inventory_position.aging_signal.oldest_purchase_date}${ageText}.`
|
||||
);
|
||||
}
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
function derivedBusinessOverviewInferenceLine(pilot: AssistantMcpDiscoveryPilotExecutionContract): string | null {
|
||||
const overview = pilot.derived_business_overview;
|
||||
if (!overview) {
|
||||
return null;
|
||||
}
|
||||
if (
|
||||
overview.incoming_customer_revenue.rows_with_amount <= 0 &&
|
||||
overview.outgoing_supplier_payout.rows_with_amount <= 0
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
return [
|
||||
`Расчетное нетто по найденным строкам: ${overview.net_amount_human_ru}; ${businessOverviewNetDirectionRu(overview.net_direction)}.`,
|
||||
"Это нормальный операционный сигнал, но не прибыль и не маржа: для управленческого вывода нужны отдельные расходы, себестоимость, долги, налоги и склад."
|
||||
].join(" ");
|
||||
}
|
||||
|
||||
function businessOverviewUnknownLines(pilot: AssistantMcpDiscoveryPilotExecutionContract): string[] {
|
||||
if (!pilot.derived_business_overview) {
|
||||
return userFacingUnknowns(pilot.evidence.unknown_facts);
|
||||
}
|
||||
return userFacingUnknowns(pilot.evidence.unknown_facts);
|
||||
}
|
||||
|
||||
export function buildAssistantMcpDiscoveryAnswerDraft(
|
||||
pilot: AssistantMcpDiscoveryPilotExecutionContract
|
||||
): AssistantMcpDiscoveryAnswerDraftContract {
|
||||
@@ -912,6 +1078,7 @@ export function buildAssistantMcpDiscoveryAnswerDraft(
|
||||
pushReason(reasonCodes, "answer_contains_bounded_inference");
|
||||
}
|
||||
const derivedInferenceLine =
|
||||
derivedBusinessOverviewInferenceLine(pilot) ??
|
||||
derivedActivityInferenceLine(pilot) ??
|
||||
derivedMetadataInferenceLine(pilot) ??
|
||||
derivedRankedValueFlowInferenceLine(pilot) ??
|
||||
@@ -929,10 +1096,28 @@ export function buildAssistantMcpDiscoveryAnswerDraft(
|
||||
derivedBidirectionalValueFlowMonthlyLines(pilot).length > 0
|
||||
? derivedBidirectionalValueFlowMonthlyLines(pilot)
|
||||
: derivedValueFlowMonthlyLines(pilot);
|
||||
const businessOverviewLines = derivedBusinessOverviewConfirmedLines(pilot);
|
||||
if (monthlyConfirmedLines.length > 0) {
|
||||
pushReason(reasonCodes, "answer_contains_monthly_breakdown");
|
||||
}
|
||||
const confirmedLines = pilot.derived_ranked_value_flow && derivedValueLine
|
||||
if (businessOverviewLines.length > 0) {
|
||||
pushReason(reasonCodes, "answer_contains_business_overview");
|
||||
}
|
||||
if (pilot.derived_business_overview?.tax_position) {
|
||||
pushReason(reasonCodes, "answer_contains_business_overview_tax_position");
|
||||
}
|
||||
if (pilot.derived_business_overview?.debt_position) {
|
||||
pushReason(reasonCodes, "answer_contains_business_overview_debt_position");
|
||||
}
|
||||
if (pilot.derived_business_overview?.debt_open_settlement_quality) {
|
||||
pushReason(reasonCodes, "answer_contains_business_overview_open_settlement_quality");
|
||||
}
|
||||
if (pilot.derived_business_overview?.inventory_position) {
|
||||
pushReason(reasonCodes, "answer_contains_business_overview_inventory_position");
|
||||
}
|
||||
const confirmedLines = businessOverviewLines.length > 0
|
||||
? businessOverviewLines
|
||||
: pilot.derived_ranked_value_flow && derivedValueLine
|
||||
? [derivedValueLine]
|
||||
: derivedValueLine
|
||||
? [...pilot.evidence.confirmed_facts, derivedValueLine, ...monthlyConfirmedLines]
|
||||
@@ -941,7 +1126,9 @@ export function buildAssistantMcpDiscoveryAnswerDraft(
|
||||
: derivedMetadataLine
|
||||
? [derivedMetadataLine]
|
||||
: pilot.evidence.confirmed_facts;
|
||||
const unknownLines = pilot.derived_metadata_surface
|
||||
const unknownLines = pilot.derived_business_overview
|
||||
? businessOverviewUnknownLines(pilot)
|
||||
: pilot.derived_metadata_surface
|
||||
? pilot.derived_metadata_surface.available_fields.length > 0
|
||||
? userFacingUnknowns(pilot.evidence.unknown_facts)
|
||||
: ["Детальный список полей этих объектов этим шагом не получен."]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -682,6 +682,12 @@ function hasLifecycleSignal(text: string): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
function hasBusinessOverviewSignal(text: string): boolean {
|
||||
return /(?:\u0431\u0438\u0437\u043d\u0435\u0441[-\s]?\u043e\u0431\u0437\u043e\u0440|\u0431\u0438\u0437\u043d\u0435\u0441[-\s]?\u0430\u0443\u0434\u0438\u0442|\u043f\u043e\u043b\u043d\w*\s+\u0430\u043d\u0430\u043b\u0438\u0437\s+(?:\u043a\u043e\u043c\u043f\u0430\u043d|\u0431\u0438\u0437\u043d\u0435\u0441|\u0434\u0435\u044f\u0442\u0435\u043b)|\u0441\u0432\u043e\u0434\u043d\w*\s+\u0430\u043d\u0430\u043b\u0438\u0437\s+(?:\u043a\u043e\u043c\u043f\u0430\u043d|\u0431\u0438\u0437\u043d\u0435\u0441|\u0434\u0435\u044f\u0442\u0435\u043b)|\u043a\u0430\u043a\s+\u0442\u044b\s+\u043e\u0446\u0435\u043d(?:\u0438\u0448\u044c|\u0438)\s+\u0434\u0435\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442|\u043a\u043e\u043c\u043f\u0430\u043d(?:\u0438\u0438|\u0438\u044e|\u0438\u044f)\s+\u0432\s+\u0446\u0435\u043b\u043e\u043c|company\s+(?:analysis|overview)|business\s+(?:overview|audit)|llm[-\s]?audit|бизнес[-\s]?обзор|бизнес[-\s]?аудит)/iu.test(
|
||||
text
|
||||
);
|
||||
}
|
||||
|
||||
function hasValueFlowSignal(text: string): boolean {
|
||||
return /(?:оборот|выручк|оплат|плат[её]ж|заплат|перечисл|списан|расход|исходящ|входящ|получ(?:ил|ено|ен)|поступил|поступлен|денежн[а-яёa-z0-9_-]*\s+поток|(?<!\p{L})заработ(?:ал|али|ало|аем|ает|ать|ано|ок)(?!\p{L})|supplier|value[-\s]?flow|turnover|revenue|payment|payout|outflow|cash\s+flow|\bearn(?:ed|ing|ings)?\b)/iu.test(
|
||||
text
|
||||
@@ -737,7 +743,14 @@ function extractOrganizationScopeFromRawText(value: unknown): string | null {
|
||||
if (!match?.[1]) {
|
||||
return null;
|
||||
}
|
||||
return toNonEmptyString(match[1]);
|
||||
return toNonEmptyString(
|
||||
match[1]
|
||||
.replace(
|
||||
/\s+(?:\u043f\u043e\s+\u0434\u0430\u043d\u043d\u044b\u043c\s+1\u0441|\u0432\s+\u0446\u0435\u043b\u043e\u043c|\u0437\u0430\s+(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{2}|(?:19|20)\d{2})(?:\s+\u0433(?:\u043e\u0434|\.)?)?|\u043d\u0430\s+(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{2}|(?:19|20)\d{2})|\u0437\u0430\s+\u0432\u0441[\u0435\u0451]\s+(?:\u0434\u043e\u0441\u0442\u0443\u043f\p{L}+\s+)?\u0432\u0440\u0435\u043c\u044f|\u0437\u0430\s+\u0432\u0435\u0441\u044c\s+(?:\u0434\u043e\u0441\u0442\u0443\u043f\p{L}+\s+)?\u043f\u0435\u0440\u0438\u043e\u0434|\u0437\u0430\s+\u0432\u0441\u044e\s+\u0438\u0441\u0442\u043e\u0440\u0438(?:\u044e|\u0438)|\u0434\u0430\u0439\s+\u0431\u0438\u0437\u043d\u0435\u0441-?\u043e\u0431\u0437\u043e\u0440|\u0431\u0438\u0437\u043d\u0435\u0441-?\u043e\u0431\u0437\u043e\u0440|\u043d\u043e\s+\u043d\u0435).*$/iu,
|
||||
""
|
||||
)
|
||||
.trim()
|
||||
);
|
||||
}
|
||||
|
||||
function hasMonthlyAggregationSignal(text: string): boolean {
|
||||
@@ -747,7 +760,7 @@ function hasMonthlyAggregationSignal(text: string): boolean {
|
||||
}
|
||||
|
||||
function hasAllTimeScopeHint(text: string): boolean {
|
||||
return /(?:\u0437\u0430\s+\u0432\u0441[\u0435\u0451]\s+\u0432\u0440\u0435\u043c\u044f|\u0437\u0430\s+\u0432\u0435\u0441\u044c\s+\u043f\u0435\u0440\u0438\u043e\u0434|\u0437\u0430\s+\u0432\u0441\u044e\s+\u0438\u0441\u0442\u043e\u0440\u0438(?:\u044e|\u0438)|\u0437\u0430\s+\u043b\u044e\u0431\u043e\u0439\s+\u043f\u0435\u0440\u0438\u043e\u0434|for\s+all\s+time|all\s+time|entire\s+period|full\s+history|any\s+period)/iu.test(
|
||||
return /(?:\u0437\u0430\s+\u0432\u0441[\u0435\u0451]\s+(?:\u0434\u043e\u0441\u0442\u0443\u043f\p{L}+\s+)?\u0432\u0440\u0435\u043c\u044f|\u0437\u0430\s+\u0432\u0435\u0441\u044c\s+(?:\u0434\u043e\u0441\u0442\u0443\u043f\p{L}+\s+)?\u043f\u0435\u0440\u0438\u043e\u0434|\u0437\u0430\s+\u0432\u0441\u044e\s+\u0438\u0441\u0442\u043e\u0440\u0438(?:\u044e|\u0438)|\u0437\u0430\s+\u043b\u044e\u0431\u043e\u0439\s+\u043f\u0435\u0440\u0438\u043e\u0434|for\s+all\s+time|all\s+time|entire\s+period|full\s+history|any\s+period)/iu.test(
|
||||
text
|
||||
);
|
||||
}
|
||||
@@ -1000,6 +1013,22 @@ function hasExplicitDateScopeLiteral(text: string): boolean {
|
||||
return /(?:\b(?:19|20)\d{2}\b|\b\d{4}-\d{2}-\d{2}\b|\b\d{4}-\d{2}\b)/iu.test(text);
|
||||
}
|
||||
|
||||
function stripNegatedTaxDateScopeClauses(text: string): string {
|
||||
const dateScopeLiteral = String.raw`\b(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{2}|(?:19|20)\d{2})\b`;
|
||||
const taxToken = String.raw`(?:\u043d\u0434\u0441|vat)`;
|
||||
const scopeToken = String.raw`(?:\u0437\u0430|\u043d\u0430|\u043f\u043e|for|in)`;
|
||||
const negatedVerb = String.raw`(?:\u0442\u0430\u0449\u0438(?:\u0442\u044c)?|\u0431\u0435\u0440\u0438|\u0431\u0440\u0430\u0442\u044c|\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439(?:\u0442\u0435)?|\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c|\u0441\u0447\u0438\u0442\u0430\u0439(?:\u0442\u0435)?|\u0441\u0447\u0438\u0442\u0430\u0442\u044c|\u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u0439(?:\u0442\u0435)?|\u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u0442\u044c|\u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438|\u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442\u044c|pull|reuse|use|carry)`;
|
||||
const direct = new RegExp(
|
||||
String.raw`(?:^|[\s,;:])(?:\u043d\u0435\s+${negatedVerb}\s+${taxToken}\s+${scopeToken}\s+${dateScopeLiteral}|\u0431\u0435\u0437\s+${taxToken}\s+${scopeToken}\s+${dateScopeLiteral}|do\s+not\s+(?:${negatedVerb}\s+)?${taxToken}\s+${scopeToken}\s+${dateScopeLiteral})`,
|
||||
"giu"
|
||||
);
|
||||
const reversed = new RegExp(
|
||||
String.raw`${taxToken}\s+${scopeToken}\s+${dateScopeLiteral}\s+(?:\u043d\u0435\s+${negatedVerb}|do\s+not\s+(?:${negatedVerb})?)`,
|
||||
"giu"
|
||||
);
|
||||
return text.replace(direct, " ").replace(reversed, " ");
|
||||
}
|
||||
|
||||
function collectDateScopeFromRawText(text: string): string | null {
|
||||
const isoDate = text.match(/\b(\d{4}-\d{2}-\d{2})\b/u);
|
||||
if (isoDate?.[1]) {
|
||||
@@ -1040,6 +1069,9 @@ function semanticNeedFor(input: {
|
||||
entityResolutionSignal: boolean;
|
||||
}): string | null {
|
||||
const combined = compactLower(`${input.domain ?? ""} ${input.action ?? ""} ${input.unsupported ?? ""}`);
|
||||
if (/(?:broad_business_evaluation|broad_evaluation|business_summary|business_overview|company analysis|business audit)/iu.test(combined)) {
|
||||
return "business overview evidence with bounded analyst interpretation";
|
||||
}
|
||||
if (input.metadataSignal || /(?:metadata|schema|catalog|inspect_(?:catalog|documents|registers|fields))/iu.test(combined)) {
|
||||
return "1C metadata evidence";
|
||||
}
|
||||
@@ -1133,9 +1165,12 @@ export function buildAssistantMcpDiscoveryTurnInput(
|
||||
const rawReferentialDocumentExclusionSignal = hasReferentialDocumentExclusionFollowupSignal(
|
||||
repairedUserText ?? rawUserText ?? ""
|
||||
);
|
||||
const rawLifecycleSignal = hasLifecycleSignal(rawText);
|
||||
const rawBidirectionalValueFlowSignal = !rawLifecycleSignal && hasBidirectionalValueFlowSignal(rawText);
|
||||
const rawBusinessOverviewSignal = hasBusinessOverviewSignal(rawText);
|
||||
const rawLifecycleSignal = !rawBusinessOverviewSignal && hasLifecycleSignal(rawText);
|
||||
const rawBidirectionalValueFlowSignal =
|
||||
!rawBusinessOverviewSignal && !rawLifecycleSignal && hasBidirectionalValueFlowSignal(rawText);
|
||||
const rawValueFlowSignal =
|
||||
!rawBusinessOverviewSignal &&
|
||||
!rawLifecycleSignal &&
|
||||
(hasValueFlowSignal(rawText) || hasValueRankingSignal(rawText) || rawBidirectionalValueFlowSignal);
|
||||
const rawMetadataSignal =
|
||||
@@ -1150,9 +1185,14 @@ export function buildAssistantMcpDiscoveryTurnInput(
|
||||
rawValueFlowSignal && hasValueFlowAggregateQuestionSignal(rawText);
|
||||
const monthlyAggregationSignal = hasMonthlyAggregationSignal(rawText);
|
||||
const rawAllTimeScopeSignal = hasAllTimeScopeHint(rawText);
|
||||
const explicitDateScopeLiteralDetected = hasExplicitDateScopeLiteral(rawText);
|
||||
const dateScopeSignalText = stripNegatedTaxDateScopeClauses(rawText);
|
||||
const negatedTaxDateScopeOnlySignal =
|
||||
dateScopeSignalText !== rawText &&
|
||||
hasExplicitDateScopeLiteral(rawText) &&
|
||||
!hasExplicitDateScopeLiteral(dateScopeSignalText);
|
||||
const explicitDateScopeLiteralDetected = hasExplicitDateScopeLiteral(dateScopeSignalText);
|
||||
const relativeCurrentDateHintDetected = hasRelativeCurrentDateHint(rawText);
|
||||
const rawDateScope = collectDateScopeFromRawText(rawText);
|
||||
const rawDateScope = collectDateScopeFromRawText(dateScopeSignalText);
|
||||
const rawMetadataScopeHint = rawMetadataSignal ? metadataScopeHintFromRawText(rawText) : null;
|
||||
const rawEntityCandidate = rawEntityResolutionSignal ? rawEntityResolutionCandidate(rawEntitySourceText) : null;
|
||||
const entityResolutionClarificationCandidate =
|
||||
@@ -1171,6 +1211,12 @@ export function buildAssistantMcpDiscoveryTurnInput(
|
||||
const rawAggregationAxis = toNonEmptyString(assistantTurnMeaning?.asked_aggregation_axis);
|
||||
const unsupported = toNonEmptyString(assistantTurnMeaning?.unsupported_but_understood_family);
|
||||
const broadBusinessEvaluationUnsupported = unsupported === "broad_business_evaluation";
|
||||
const businessOverviewSignal =
|
||||
rawBusinessOverviewSignal ||
|
||||
broadBusinessEvaluationUnsupported ||
|
||||
rawDomain === "business_summary" ||
|
||||
rawDomain === "business_overview" ||
|
||||
rawAction === "broad_evaluation";
|
||||
const explicitIntentCandidate = toNonEmptyString(assistantTurnMeaning?.explicit_intent_candidate);
|
||||
const currentTurnDocumentLaneSignal = rawAction === "list_documents";
|
||||
const currentTurnMovementLaneSignal = rawAction === "list_movements";
|
||||
@@ -1553,11 +1599,13 @@ export function buildAssistantMcpDiscoveryTurnInput(
|
||||
? followupSeed.unsupported
|
||||
: null;
|
||||
const lifecycleSignal =
|
||||
rawLifecycleSignal || seededDomain === "counterparty_lifecycle";
|
||||
!businessOverviewSignal && (rawLifecycleSignal || seededDomain === "counterparty_lifecycle");
|
||||
const bidirectionalValueFlowSignal =
|
||||
!businessOverviewSignal &&
|
||||
!lifecycleSignal &&
|
||||
(rawBidirectionalValueFlowSignal || seededAction === "net_value_flow");
|
||||
const valueFlowSignal =
|
||||
!businessOverviewSignal &&
|
||||
!lifecycleSignal &&
|
||||
!metadataGroundedMovementLaneApplicable &&
|
||||
(rawValueFlowSignal || seededDomain === "counterparty_value");
|
||||
@@ -1568,9 +1616,9 @@ export function buildAssistantMcpDiscoveryTurnInput(
|
||||
const semanticDataNeed = metadataAmbiguityLaneClarificationApplicable
|
||||
? "metadata lane clarification"
|
||||
: semanticNeedFor({
|
||||
domain: rawDomain ?? seededDomain,
|
||||
action: rawAction ?? seededAction,
|
||||
unsupported: broadBusinessEvaluationUnsupported ? seededUnsupported : unsupported ?? seededUnsupported,
|
||||
domain: businessOverviewSignal ? "business_overview" : rawDomain ?? seededDomain,
|
||||
action: businessOverviewSignal ? "broad_evaluation" : rawAction ?? seededAction,
|
||||
unsupported: businessOverviewSignal ? "broad_business_evaluation" : unsupported ?? seededUnsupported,
|
||||
lifecycleSignal,
|
||||
valueFlowSignal,
|
||||
metadataSignal: rawMetadataSignal || effectiveMetadataFollowupSeedApplicable,
|
||||
@@ -1710,30 +1758,48 @@ export function buildAssistantMcpDiscoveryTurnInput(
|
||||
const clarificationLoopStillNeedsPeriod = Boolean(
|
||||
followupSeed.loopStatus === "awaiting_clarification" && followupSeed.loopPendingAxes.includes("period")
|
||||
);
|
||||
const businessOverviewRawWithoutDateScope = Boolean(
|
||||
businessOverviewSignal &&
|
||||
!rawAllTimeScopeSignal &&
|
||||
!explicitDateScopeLiteralDetected &&
|
||||
!rawDateScope &&
|
||||
!relativeCurrentDateHintDetected
|
||||
);
|
||||
const predecomposeDateScopeCountsAsCurrentTurnPeriod = Boolean(
|
||||
predecomposeDateScope &&
|
||||
!isImplicitCurrentDateScope(predecomposeDateScope) &&
|
||||
!businessOverviewRawWithoutDateScope
|
||||
);
|
||||
const currentTurnCarriesExplicitPeriod = Boolean(
|
||||
explicitDateScopeLiteralDetected ||
|
||||
rawDateScope ||
|
||||
relativeCurrentDateHintDetected ||
|
||||
(predecomposeDateScope && !isImplicitCurrentDateScope(predecomposeDateScope))
|
||||
predecomposeDateScopeCountsAsCurrentTurnPeriod
|
||||
);
|
||||
const suppressImplicitCurrentDateScope = Boolean(
|
||||
!currentTurnCarriesExplicitPeriod &&
|
||||
(clarificationLoopStillNeedsPeriod ||
|
||||
businessOverviewSignal ||
|
||||
openScopeValueFlowWithoutResolvedCounterparty ||
|
||||
(valueFlowOrganizationStaysScope && (Boolean(followupSeed.rankingNeed) || bidirectionalValueFlowSignal)))
|
||||
);
|
||||
const suppressNegatedTaxOnlyDateScope = Boolean(businessOverviewSignal && negatedTaxDateScopeOnlySignal);
|
||||
const normalizedPredecomposeDateScope =
|
||||
(rawEntitySearchOverridesStaleScope && !currentTurnCarriesExplicitPeriod) ||
|
||||
suppressNegatedTaxOnlyDateScope ||
|
||||
businessOverviewRawWithoutDateScope ||
|
||||
(suppressImplicitCurrentDateScope && isImplicitCurrentDateScope(predecomposeDateScope))
|
||||
? null
|
||||
: predecomposeDateScope;
|
||||
const normalizedAssistantTurnMeaningDateScope =
|
||||
rawEntitySearchOverridesStaleScope ||
|
||||
suppressNegatedTaxOnlyDateScope ||
|
||||
(suppressImplicitCurrentDateScope && isImplicitCurrentDateScope(assistantTurnMeaningDateScope))
|
||||
? null
|
||||
: assistantTurnMeaningDateScope;
|
||||
const normalizedFollowupDateScope =
|
||||
rawEntitySearchOverridesStaleScope ||
|
||||
suppressNegatedTaxOnlyDateScope ||
|
||||
(suppressImplicitCurrentDateScope && isImplicitCurrentDateScope(followupSeed.dateScope))
|
||||
? null
|
||||
: followupSeed.dateScope;
|
||||
@@ -1757,7 +1823,9 @@ export function buildAssistantMcpDiscoveryTurnInput(
|
||||
|
||||
const turnMeaning: AssistantMcpDiscoveryTurnMeaningRef = {
|
||||
asked_domain_family:
|
||||
lifecycleSignal
|
||||
businessOverviewSignal
|
||||
? "business_overview"
|
||||
: lifecycleSignal
|
||||
? "counterparty_lifecycle"
|
||||
: valueFlowSignal
|
||||
? "counterparty_value"
|
||||
@@ -1770,9 +1838,11 @@ export function buildAssistantMcpDiscoveryTurnInput(
|
||||
: rawMetadataSignal || effectiveMetadataFollowupSeedApplicable
|
||||
? "metadata"
|
||||
: rawDomain ?? seededDomain,
|
||||
asked_action_family: lifecycleSignal
|
||||
? "activity_duration"
|
||||
: valueFlowSignal
|
||||
asked_action_family: businessOverviewSignal
|
||||
? "broad_evaluation"
|
||||
: lifecycleSignal
|
||||
? "activity_duration"
|
||||
: valueFlowSignal
|
||||
? bidirectionalValueFlowSignal
|
||||
? "net_value_flow"
|
||||
: payoutSignal
|
||||
@@ -1792,7 +1862,7 @@ export function buildAssistantMcpDiscoveryTurnInput(
|
||||
valueFlowSignal && followupSeed.rankingNeed && !rawEntitySearchOverridesStaleScope
|
||||
? followupSeed.rankingNeed
|
||||
: undefined,
|
||||
explicit_entity_candidates: entityCandidates,
|
||||
explicit_entity_candidates: businessOverviewSignal ? [] : entityCandidates,
|
||||
metadata_ambiguity_entity_sets:
|
||||
metadataAmbiguityLaneClarificationApplicable && followupSeed.metadataAmbiguityEntitySets.length > 0
|
||||
? followupSeed.metadataAmbiguityEntitySets
|
||||
@@ -1802,7 +1872,9 @@ export function buildAssistantMcpDiscoveryTurnInput(
|
||||
explicit_date_scope: explicitDateScope,
|
||||
subject_resolution_optional: metadataScopedLaneWithoutSubject || undefined,
|
||||
unsupported_but_understood_family:
|
||||
unsupported ??
|
||||
businessOverviewSignal
|
||||
? "broad_business_evaluation"
|
||||
: unsupported ??
|
||||
(lifecycleSignal
|
||||
? "counterparty_lifecycle"
|
||||
: valueFlowSignal
|
||||
@@ -1826,6 +1898,7 @@ export function buildAssistantMcpDiscoveryTurnInput(
|
||||
: null),
|
||||
stale_replay_forbidden: Boolean(
|
||||
assistantTurnMeaning?.stale_replay_forbidden ||
|
||||
businessOverviewSignal ||
|
||||
unsupported ||
|
||||
lifecycleSignal ||
|
||||
valueFlowSignal ||
|
||||
@@ -1886,7 +1959,7 @@ export function buildAssistantMcpDiscoveryTurnInput(
|
||||
);
|
||||
|
||||
const runDiscovery = shouldRunDiscovery({
|
||||
unsupported: broadBusinessEvaluationUnsupported ? seededUnsupported : unsupported ?? seededUnsupported,
|
||||
unsupported: businessOverviewSignal ? "broad_business_evaluation" : unsupported ?? seededUnsupported,
|
||||
lifecycleSignal,
|
||||
valueFlowSignal,
|
||||
metadataSignal: rawMetadataSignal || effectiveMetadataFollowupSeedApplicable,
|
||||
@@ -1902,6 +1975,7 @@ export function buildAssistantMcpDiscoveryTurnInput(
|
||||
metadataGroundedDocumentLaneApplicable ||
|
||||
groundedValueFlowFollowupApplicable,
|
||||
forceDiscoveryOverExplicitIntent:
|
||||
businessOverviewSignal ||
|
||||
Boolean(entityResolutionClarificationCandidate) ||
|
||||
organizationClarificationFollowupApplicable ||
|
||||
periodClarificationFollowupApplicable ||
|
||||
@@ -1976,6 +2050,9 @@ export function buildAssistantMcpDiscoveryTurnInput(
|
||||
if (rawAllTimeScopeSignal) {
|
||||
pushReason(reasonCodes, "mcp_discovery_all_time_scope_signal_detected");
|
||||
}
|
||||
if (suppressNegatedTaxOnlyDateScope) {
|
||||
pushReason(reasonCodes, "mcp_discovery_negated_tax_period_scope_suppressed");
|
||||
}
|
||||
if (followupDiscoverySeedApplicable) {
|
||||
pushReason(reasonCodes, "mcp_discovery_seeded_from_followup_context");
|
||||
}
|
||||
@@ -2054,8 +2131,8 @@ export function buildAssistantMcpDiscoveryTurnInput(
|
||||
if (unsupported) {
|
||||
pushReason(reasonCodes, "mcp_discovery_unsupported_but_understood_turn");
|
||||
}
|
||||
if (broadBusinessEvaluationUnsupported) {
|
||||
pushReason(reasonCodes, "mcp_discovery_broad_business_evaluation_kept_in_living_chat");
|
||||
if (businessOverviewSignal) {
|
||||
pushReason(reasonCodes, "mcp_discovery_broad_business_evaluation_route_candidate");
|
||||
}
|
||||
if (
|
||||
!(valueFlowOrganizationStaysScope && normalizedPredecomposeCounterparty === explicitOrganizationScope) &&
|
||||
|
||||
@@ -122,6 +122,13 @@ function detectBroadBusinessEvaluation(text) {
|
||||
if (!normalized) {
|
||||
return null;
|
||||
}
|
||||
if (
|
||||
/(?:\u0431\u0438\u0437\u043d\u0435\u0441[-\s]?\u043e\u0431\u0437\u043e\u0440|\u0431\u0438\u0437\u043d\u0435\u0441[-\s]?\u0430\u0443\u0434\u0438\u0442|\u043f\u043e\u043b\u043d\w*\s+\u0430\u043d\u0430\u043b\u0438\u0437\s+(?:\u043a\u043e\u043c\u043f\u0430\u043d|\u0431\u0438\u0437\u043d\u0435\u0441|\u0434\u0435\u044f\u0442\u0435\u043b)|\u0441\u0432\u043e\u0434\u043d\w*\s+\u0430\u043d\u0430\u043b\u0438\u0437\s+(?:\u043a\u043e\u043c\u043f\u0430\u043d|\u0431\u0438\u0437\u043d\u0435\u0441|\u0434\u0435\u044f\u0442\u0435\u043b)|\u043a\u0430\u043a\s+\u0442\u044b\s+\u043e\u0446\u0435\u043d(?:\u0438\u0448\u044c|\u0438)\s+\u0434\u0435\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442|\u043a\u043e\u043c\u043f\u0430\u043d(?:\u0438\u0438|\u0438\u044e|\u0438\u044f)\s+\u0432\s+\u0446\u0435\u043b\u043e\u043c|company\s+(?:analysis|overview)|business\s+(?:overview|audit)|llm[-\s]?audit|бизнес[-\s]?обзор|бизнес[-\s]?аудит)/iu.test(normalized)
|
||||
) {
|
||||
return {
|
||||
family: "broad_business_evaluation"
|
||||
};
|
||||
}
|
||||
if (
|
||||
/(?:как\s+ты\s+оценишь\s+деятельност[ьи]\s+компан|оценк[аи]?\s+деятельност[ьи]\s+компан|оцени\s+(?:компан|бизнес|деятельност)|(?:полный|сводный|нормальн\w*|взросл\w*)\s+анализ\s+(?:компан|бизнес|деятельност)|проанализируй\s+(?:компан|бизнес|деятельност)|(?:что\s+думаешь|какое\s+мнение)\s+(?:о|по)\s+(?:компан|бизнес)|(?:llm[-\s]?)?аудит\s+(?:компан|бизнес)|что\s+у\s+нас\s+вообще\s+происход|где\s+главн(?:ые|ый)\s+риски|как\s+у\s+нас\s+дела\s+по\s+компан)/iu.test(
|
||||
normalized
|
||||
@@ -232,7 +239,7 @@ export function createAssistantTurnMeaningPolicy(deps = {}) {
|
||||
asked_domain_family: askedDomainFamily,
|
||||
asked_action_family: askedActionFamily,
|
||||
explicit_intent_candidate: explicitIntentCandidate,
|
||||
explicit_entity_candidates: buildEntityCandidates(counterpartyTurnover),
|
||||
explicit_entity_candidates: broadBusinessEvaluation?.family ? [] : buildEntityCandidates(counterpartyTurnover),
|
||||
meaning_confidence: broadBusinessEvaluation?.family
|
||||
? "medium"
|
||||
: supportedIntent?.confidence ?? (counterpartyTurnover?.family ? "medium" : "low"),
|
||||
|
||||
Reference in New Issue
Block a user