АРЧ АП11 - Архитектура после регресса: Архитектура: централизовать address debug context для memory recap и living-chat follow-up
This commit is contained in:
@@ -27,6 +27,12 @@ export interface AssistantContinuitySnapshot {
|
||||
hasGroundedInventoryContext: boolean;
|
||||
}
|
||||
|
||||
export interface AssistantAddressDebugContextFacts {
|
||||
item: string | null;
|
||||
organization: string | null;
|
||||
scopedDate: string | null;
|
||||
}
|
||||
|
||||
export interface AssistantOrganizationAuthorityInput {
|
||||
sessionItems?: unknown[];
|
||||
sessionKnownOrganizations?: unknown[];
|
||||
@@ -118,6 +124,17 @@ export function readAddressDebugScopedDate(debug: Record<string, unknown> | null
|
||||
);
|
||||
}
|
||||
|
||||
export function resolveAddressDebugContextFacts(
|
||||
debug: Record<string, unknown> | null,
|
||||
toNonEmptyString: (value: unknown) => string | null = fallbackToNonEmptyString
|
||||
): AssistantAddressDebugContextFacts {
|
||||
return {
|
||||
item: readAddressDebugItem(debug, toNonEmptyString),
|
||||
organization: readAddressDebugOrganization(debug, toNonEmptyString),
|
||||
scopedDate: readAddressDebugScopedDate(debug)
|
||||
};
|
||||
}
|
||||
|
||||
export function buildInventoryRootFrameFromAddressDebug(
|
||||
debug: Record<string, unknown> | null,
|
||||
toNonEmptyString: (value: unknown) => string | null = fallbackToNonEmptyString
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
// @ts-nocheck
|
||||
|
||||
import {
|
||||
formatIsoDateForReply,
|
||||
isGroundedAddressDebug,
|
||||
readAddressDebugFilters,
|
||||
readAddressDebugItem,
|
||||
readAddressDebugOrganization,
|
||||
readAddressDebugScopedDate,
|
||||
resolveAddressDebugContextFacts,
|
||||
resolveAssistantContinuitySnapshot
|
||||
} from "./assistantContinuityPolicy";
|
||||
|
||||
@@ -92,19 +88,9 @@ export function buildInventoryHistoryCapabilityFollowupReply(input: {
|
||||
addressDebug: Record<string, unknown> | null;
|
||||
toNonEmptyString: (value: unknown) => string | null;
|
||||
}): string {
|
||||
const rootFrameContext =
|
||||
input.addressDebug?.address_root_frame_context &&
|
||||
typeof input.addressDebug.address_root_frame_context === "object"
|
||||
? (input.addressDebug.address_root_frame_context as Record<string, unknown>)
|
||||
: null;
|
||||
const extractedFilters = readAddressDebugFilters(input.addressDebug);
|
||||
const organization =
|
||||
input.organization ??
|
||||
input.toNonEmptyString(rootFrameContext?.organization) ??
|
||||
input.toNonEmptyString(extractedFilters?.organization);
|
||||
const lastAsOfDate =
|
||||
formatIsoDateForReply(rootFrameContext?.as_of_date) ??
|
||||
formatIsoDateForReply(extractedFilters?.as_of_date);
|
||||
const contextFacts = resolveAddressDebugContextFacts(input.addressDebug, input.toNonEmptyString);
|
||||
const organization = input.organization ?? contextFacts.organization;
|
||||
const lastAsOfDate = contextFacts.scopedDate;
|
||||
const organizationPart = organization ? ` по компании «${organization}»` : "";
|
||||
const referenceLine = lastAsOfDate
|
||||
? `Да, могу. Сейчас мы уже смотрели складской срез${organizationPart} на ${lastAsOfDate}.`
|
||||
@@ -135,7 +121,7 @@ function buildRecapFactLine(input: {
|
||||
organization: string | null;
|
||||
}): string | null {
|
||||
const detectedIntent = String(input.debug?.detected_intent ?? "");
|
||||
const scopedDate = readAddressDebugScopedDate(input.debug);
|
||||
const scopedDate = resolveAddressDebugContextFacts(input.debug).scopedDate;
|
||||
const itemPart = input.item ? `по позиции «${input.item}»` : null;
|
||||
const organizationPart = input.organization ? `по компании «${input.organization}»` : null;
|
||||
const datePart = scopedDate ? ` на ${scopedDate}` : "";
|
||||
@@ -192,8 +178,9 @@ function collectRecentRecapFacts(input: {
|
||||
if (!isGroundedAddressDebug(item.debug, input.toNonEmptyString)) {
|
||||
continue;
|
||||
}
|
||||
const debugItem = readAddressDebugItem(item.debug, input.toNonEmptyString);
|
||||
const debugOrganization = readAddressDebugOrganization(item.debug, input.toNonEmptyString);
|
||||
const debugContext = resolveAddressDebugContextFacts(item.debug, input.toNonEmptyString);
|
||||
const debugItem = debugContext.item;
|
||||
const debugOrganization = debugContext.organization;
|
||||
const itemMatches = currentItemKey ? normalizeRecapIdentity(debugItem) === currentItemKey : false;
|
||||
const organizationMatches = currentOrganizationKey
|
||||
? normalizeRecapIdentity(debugOrganization) === currentOrganizationKey
|
||||
@@ -228,21 +215,10 @@ export function buildAddressMemoryRecapReply(input: {
|
||||
sessionItems?: unknown[];
|
||||
toNonEmptyString: (value: unknown) => string | null;
|
||||
}): string {
|
||||
const extractedFilters =
|
||||
input.addressDebug?.extracted_filters && typeof input.addressDebug.extracted_filters === "object"
|
||||
? (input.addressDebug.extracted_filters as Record<string, unknown>)
|
||||
: null;
|
||||
const rootFrameContext =
|
||||
input.addressDebug?.address_root_frame_context &&
|
||||
typeof input.addressDebug.address_root_frame_context === "object"
|
||||
? (input.addressDebug.address_root_frame_context as Record<string, unknown>)
|
||||
: null;
|
||||
const item = readAddressDebugItem(input.addressDebug, input.toNonEmptyString);
|
||||
const organization =
|
||||
input.organization ??
|
||||
input.toNonEmptyString(extractedFilters?.organization) ??
|
||||
input.toNonEmptyString(rootFrameContext?.organization);
|
||||
const scopedDate = readAddressDebugScopedDate(input.addressDebug);
|
||||
const contextFacts = resolveAddressDebugContextFacts(input.addressDebug, input.toNonEmptyString);
|
||||
const item = contextFacts.item;
|
||||
const organization = input.organization ?? contextFacts.organization;
|
||||
const scopedDate = contextFacts.scopedDate;
|
||||
const recapFacts = collectRecentRecapFacts({
|
||||
sessionItems: input.sessionItems,
|
||||
item,
|
||||
|
||||
Reference in New Issue
Block a user