ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Рефакторинг этапов 2.772.80 - Убрано as any из адресного response-runtime и добавил явную нормализацию перед финализацией / Убран cast в builderе deep-response composition

This commit is contained in:
2026-04-11 10:35:29 +03:00
parent 9f3749fd4a
commit dedf193542
6 changed files with 532 additions and 59 deletions
@@ -2,6 +2,128 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.runAssistantAddressLaneResponseRuntime = runAssistantAddressLaneResponseRuntime;
const assistantAddressTurnFinalizeRuntimeAdapter_1 = require("./assistantAddressTurnFinalizeRuntimeAdapter");
function toRecordObject(value) {
if (!value || typeof value !== "object") {
return null;
}
return value;
}
function toNullableString(value) {
if (typeof value !== "string") {
return null;
}
const trimmed = value.trim();
return trimmed.length > 0 ? trimmed : null;
}
function toNullableBoolean(value) {
if (typeof value === "boolean") {
return value;
}
return undefined;
}
function normalizeAddressReplyType(value) {
return value === "factual" || value === "partial_coverage" ? value : "partial_coverage";
}
function normalizeAddressLaneDebug(value) {
return (toRecordObject(value) ?? {});
}
function normalizeCarryoverMeta(value) {
const source = toRecordObject(value);
if (!source) {
return null;
}
const followupContext = toRecordObject(source.followupContext);
const previousAddressIntent = toNullableString(source.previousAddressIntent) ??
toNullableString(followupContext?.previous_intent);
const previousAddressAnchor = toNullableString(source.previousAddressAnchor) ??
toNullableString(followupContext?.previous_anchor);
if (!previousAddressIntent && !previousAddressAnchor) {
return null;
}
return {
previousAddressIntent,
previousAddressAnchor
};
}
function normalizeLlmPreDecomposeMeta(value) {
const source = toRecordObject(value);
if (!source) {
return null;
}
const dialogContinuationContractRaw = toRecordObject(source.dialogContinuationContract);
const addressRetryAuditRaw = toRecordObject(source.addressRetryAudit);
const predecomposeContractRaw = toRecordObject(source.predecomposeContract);
const predecomposePeriodRaw = toRecordObject(predecomposeContractRaw?.period);
const normalized = {};
const attempted = toNullableBoolean(source.attempted);
if (attempted !== undefined)
normalized.attempted = attempted;
const applied = toNullableBoolean(source.applied);
if (applied !== undefined)
normalized.applied = applied;
const provider = toNullableString(source.provider);
if (provider)
normalized.provider = provider;
const traceId = toNullableString(source.traceId);
if (traceId)
normalized.traceId = traceId;
const reason = toNullableString(source.reason);
if (reason)
normalized.reason = reason;
const fallbackRuleHit = toNullableString(source.fallbackRuleHit);
if (fallbackRuleHit)
normalized.fallbackRuleHit = fallbackRuleHit;
const sanitizedUserMessage = toNullableString(source.sanitizedUserMessage);
if (sanitizedUserMessage)
normalized.sanitizedUserMessage = sanitizedUserMessage;
const toolGateDecision = toNullableString(source.toolGateDecision);
if (toolGateDecision)
normalized.toolGateDecision = toolGateDecision;
const toolGateReason = toNullableString(source.toolGateReason);
if (toolGateReason)
normalized.toolGateReason = toolGateReason;
if (dialogContinuationContractRaw) {
const decision = toNullableString(dialogContinuationContractRaw.decision);
const targetIntent = toNullableString(dialogContinuationContractRaw.target_intent);
if (decision || targetIntent) {
normalized.dialogContinuationContract = {
decision,
target_intent: targetIntent
};
}
}
if (addressRetryAuditRaw) {
const retryAttempted = toNullableBoolean(addressRetryAuditRaw.attempted);
const retryReason = toNullableString(addressRetryAuditRaw.reason);
const initialLimitedCategory = toNullableString(addressRetryAuditRaw.initial_limited_category);
const retryResultCategory = toNullableString(addressRetryAuditRaw.retry_result_category);
if (retryAttempted !== undefined ||
retryReason ||
initialLimitedCategory ||
retryResultCategory) {
normalized.addressRetryAudit = {
attempted: retryAttempted,
reason: retryReason,
initial_limited_category: initialLimitedCategory,
retry_result_category: retryResultCategory
};
}
}
if (predecomposeContractRaw) {
const intent = toNullableString(predecomposeContractRaw.intent);
const aggregationProfile = toNullableString(predecomposeContractRaw.aggregation_profile);
const periodScope = toNullableString(predecomposePeriodRaw?.scope);
if (intent || aggregationProfile || periodScope) {
normalized.predecomposeContract = {
intent,
aggregation_profile: aggregationProfile,
period: periodScope ? { scope: periodScope } : null
};
}
}
const hasUsefulField = Object.values(normalized).some((item) => item !== undefined && item !== null);
return hasUsefulField ? normalized : null;
}
function runAssistantAddressLaneResponseRuntime(input) {
const finalizeAddressTurnSafe = input.finalizeAddressTurn ?? assistantAddressTurnFinalizeRuntimeAdapter_1.finalizeAssistantAddressTurn;
const safeAddressReply = input.sanitizeOutgoingAssistantText(input.addressLane.reply_text);
@@ -27,11 +149,11 @@ function runAssistantAddressLaneResponseRuntime(input) {
userMessage: input.userMessage,
effectiveAddressUserMessage: input.effectiveAddressUserMessage,
assistantReply: safeAddressReply,
replyType: input.addressLane.reply_type,
addressLaneDebug: (input.addressLane.debug ?? null),
replyType: normalizeAddressReplyType(input.addressLane.reply_type),
addressLaneDebug: normalizeAddressLaneDebug(input.addressLane.debug),
debug,
carryoverMeta: (input.carryoverMeta ?? null),
llmPreDecomposeMeta: (input.llmPreDecomposeMeta ?? null),
carryoverMeta: normalizeCarryoverMeta(input.carryoverMeta),
llmPreDecomposeMeta: normalizeLlmPreDecomposeMeta(input.llmPreDecomposeMeta),
appendItem: input.appendItem,
getSession: input.getSession,
persistSession: input.persistSession,
@@ -3,6 +3,94 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.runAssistantDeepTurnResponseRuntime = runAssistantDeepTurnResponseRuntime;
const assistantDeepTurnPackagingRuntimeAdapter_1 = require("./assistantDeepTurnPackagingRuntimeAdapter");
const assistantDeepTurnFinalizeRuntimeAdapter_1 = require("./assistantDeepTurnFinalizeRuntimeAdapter");
function toRecordObject(value) {
if (!value || typeof value !== "object") {
return null;
}
return value;
}
function toNullableString(value) {
if (typeof value !== "string") {
return null;
}
const trimmed = value.trim();
return trimmed.length > 0 ? trimmed : null;
}
function toStringArray(value) {
if (!Array.isArray(value)) {
return [];
}
return value
.map((item) => (typeof item === "string" ? item.trim() : ""))
.filter((item) => item.length > 0);
}
function toSnapshotMode(value) {
return value === "force_snapshot" || value === "force_live" ? value : "auto";
}
function normalizeExecutionPlan(value) {
if (!Array.isArray(value)) {
return [];
}
return value.map((item, index) => {
const source = toRecordObject(item);
return {
fragment_id: toNullableString(source?.fragment_id) ?? `fragment_${index + 1}`,
requirement_ids: toStringArray(source?.requirement_ids),
route: toNullableString(source?.route) ?? "unknown_route",
should_execute: Boolean(source?.should_execute),
no_route_reason: toNullableString(source?.no_route_reason),
clarification_reason: toNullableString(source?.clarification_reason)
};
});
}
function normalizeRecordArray(value) {
if (!Array.isArray(value)) {
return [];
}
return value
.map((item) => toRecordObject(item))
.filter((item) => Boolean(item));
}
function normalizeRecord(value) {
return toRecordObject(value) ?? {};
}
function normalizeRuntimeAnalysisContext(value) {
const source = toRecordObject(value);
return {
active: Boolean(source?.active),
as_of_date: toNullableString(source?.as_of_date),
period_from: toNullableString(source?.period_from),
period_to: toNullableString(source?.period_to),
source: toNullableString(source?.source),
snapshot_mode: toSnapshotMode(source?.snapshot_mode)
};
}
function normalizeBusinessScopeResolution(value) {
const source = toRecordObject(value);
return {
business_scope_raw: toStringArray(source?.business_scope_raw),
business_scope_resolved: toStringArray(source?.business_scope_resolved),
company_grounding_applied: Boolean(source?.company_grounding_applied),
scope_resolution_reason: toStringArray(source?.scope_resolution_reason)
};
}
function normalizeAddressRuntimeMetaForDeep(value) {
const source = toRecordObject(value);
if (!source) {
return null;
}
return {
attempted: typeof source.attempted === "boolean" ? source.attempted : undefined,
applied: typeof source.applied === "boolean" ? source.applied : undefined,
reason: toNullableString(source.reason),
provider: toNullableString(source.provider),
fallbackRuleHit: toNullableString(source.fallbackRuleHit),
toolGateDecision: toNullableString(source.toolGateDecision),
toolGateReason: toNullableString(source.toolGateReason),
predecomposeContract: toRecordObject(source.predecomposeContract),
orchestrationContract: toRecordObject(source.orchestrationContract)
};
}
function runAssistantDeepTurnResponseRuntime(input) {
const runPackagingRuntimeSafe = input.runPackagingRuntime ?? assistantDeepTurnPackagingRuntimeAdapter_1.runAssistantDeepTurnPackagingRuntime;
const runFinalizeDeepTurnSafe = input.runFinalizeDeepTurn ?? assistantDeepTurnFinalizeRuntimeAdapter_1.finalizeAssistantDeepTurn;
@@ -14,33 +102,33 @@ function runAssistantDeepTurnResponseRuntime(input) {
normalized: input.normalized,
normalizedQuestion: input.normalizedQuestion,
routeSummary: input.routeSummary,
executionPlan: input.executionPlan,
executionPlan: normalizeExecutionPlan(input.executionPlan),
requirementExtractionRequirements: input.requirementExtractionRequirements,
coverageEvaluationRequirements: input.coverageEvaluationRequirements,
coverageReport: input.coverageReport,
groundingCheck: input.groundingCheck,
retrievalCalls: input.retrievalCalls,
retrievalResultsRaw: input.retrievalResultsRaw,
retrievalCalls: normalizeRecordArray(input.retrievalCalls),
retrievalResultsRaw: Array.isArray(input.retrievalResultsRaw) ? input.retrievalResultsRaw : [],
retrievalResults: input.retrievalResults,
questionTypeClass: input.questionTypeClass,
companyAnchors: input.companyAnchors,
runtimeAnalysisContext: input.runtimeAnalysisContext,
businessScopeResolution: input.businessScopeResolution,
temporalGuard: input.temporalGuard,
polarityAudit: input.polarityAudit,
claimAnchorAudit: input.claimAnchorAudit,
runtimeAnalysisContext: normalizeRuntimeAnalysisContext(input.runtimeAnalysisContext),
businessScopeResolution: normalizeBusinessScopeResolution(input.businessScopeResolution),
temporalGuard: normalizeRecord(input.temporalGuard),
polarityAudit: normalizeRecord(input.polarityAudit),
claimAnchorAudit: normalizeRecord(input.claimAnchorAudit),
targetedEvidenceAudit: input.targetedEvidenceAudit,
evidenceAdmissibilityGateAudit: input.evidenceAdmissibilityGateAudit,
rbpLiveRouteAudit: input.rbpLiveRouteAudit,
faLiveRouteAudit: input.faLiveRouteAudit,
groundedAnswerEligibilityGuard: input.groundedAnswerEligibilityGuard,
rbpLiveRouteAudit: input.rbpLiveRouteAudit ?? null,
faLiveRouteAudit: input.faLiveRouteAudit ?? null,
groundedAnswerEligibilityGuard: normalizeRecord(input.groundedAnswerEligibilityGuard),
followupStateUsage: input.followupStateUsage,
followupApplied: input.followupApplied,
composition: input.composition,
featureContractsV11: input.featureContractsV11,
featureAnswerPolicyV11: input.featureAnswerPolicyV11,
previousInvestigationState: input.previousInvestigationState ?? null,
addressRuntimeMetaForDeep: input.addressRuntimeMetaForDeep,
addressRuntimeMetaForDeep: normalizeAddressRuntimeMetaForDeep(input.addressRuntimeMetaForDeep),
extractDroppedIntentSegments: input.extractDroppedIntentSegments,
buildDebugRoutes: input.buildDebugRoutes,
extractExecutionState: input.extractExecutionState,