273 lines
16 KiB
JavaScript
273 lines
16 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.buildEmptyCoverageReport = buildEmptyCoverageReport;
|
|
exports.buildAssistantBackendErrorDebugPayload = buildAssistantBackendErrorDebugPayload;
|
|
exports.buildAddressRuntimeDebugPayload = buildAddressRuntimeDebugPayload;
|
|
exports.buildDeepAnalysisDebugPayload = buildDeepAnalysisDebugPayload;
|
|
const assistantCapabilityRuntimeBindingAdapter_1 = require("./assistantCapabilityRuntimeBindingAdapter");
|
|
const assistantRuntimeContractResolver_1 = require("./assistantRuntimeContractResolver");
|
|
const assistantStateTransitionRuntimeAdapter_1 = require("./assistantStateTransitionRuntimeAdapter");
|
|
const assistantTruthAnswerPolicyRuntimeAdapter_1 = require("./assistantTruthAnswerPolicyRuntimeAdapter");
|
|
const assistantStage4AnswerContractAudit_1 = require("./assistantStage4AnswerContractAudit");
|
|
function toAnalysisContext(input) {
|
|
if (!input.active) {
|
|
return null;
|
|
}
|
|
return {
|
|
as_of_date: input.as_of_date,
|
|
period_from: input.period_from,
|
|
period_to: input.period_to,
|
|
source: input.source,
|
|
snapshot_mode: input.snapshot_mode
|
|
};
|
|
}
|
|
function buildEmptyCoverageReport() {
|
|
return {
|
|
requirements_total: 0,
|
|
requirements_covered: 0,
|
|
requirements_uncovered: [],
|
|
requirements_partially_covered: [],
|
|
clarification_needed_for: [],
|
|
out_of_scope_requirements: []
|
|
};
|
|
}
|
|
function buildAssistantBackendErrorDebugPayload(input) {
|
|
return {
|
|
trace_id: input.traceIdFactory(),
|
|
prompt_version: "assistant_backend_error_fallback_v1",
|
|
schema_version: "assistant_backend_error_fallback_v1",
|
|
fallback_type: "unknown",
|
|
route_summary: null,
|
|
fragments: [],
|
|
requirements_extracted: [],
|
|
coverage_report: buildEmptyCoverageReport(),
|
|
routes: [],
|
|
retrieval_status: [],
|
|
retrieval_results: [],
|
|
answer_grounding_check: {
|
|
status: "no_grounded_answer",
|
|
route_subject_match: true,
|
|
missing_requirements: [],
|
|
reasons: [`backend_error:${String(input.errorMessage ?? "unknown_error").slice(0, 280)}`],
|
|
why_included_summary: [],
|
|
selection_reason_summary: []
|
|
},
|
|
dropped_intent_segments: [],
|
|
answer_structure_v11: null,
|
|
investigation_state_snapshot: null,
|
|
normalized: null
|
|
};
|
|
}
|
|
function buildAddressRuntimeDebugPayload(input) {
|
|
const grounded = input.addressDebug.response_type === "LIMITED_WITH_REASON" ? "partial" : "grounded";
|
|
const llmMeta = input.llmPreDecomposeMeta && typeof input.llmPreDecomposeMeta === "object" ? input.llmPreDecomposeMeta : null;
|
|
return {
|
|
trace_id: input.traceIdFactory(),
|
|
prompt_version: "address_query_runtime_v1",
|
|
schema_version: "address_query_runtime_v1",
|
|
fallback_type: input.addressDebug.response_type === "LIMITED_WITH_REASON" ? "partial" : "none",
|
|
route_summary: null,
|
|
fragments: [],
|
|
requirements_extracted: [],
|
|
coverage_report: buildEmptyCoverageReport(),
|
|
routes: [],
|
|
retrieval_status: [],
|
|
retrieval_results: [],
|
|
answer_grounding_check: {
|
|
status: grounded,
|
|
route_subject_match: true,
|
|
missing_requirements: [],
|
|
reasons: input.addressDebug.reasons ?? [],
|
|
why_included_summary: [],
|
|
selection_reason_summary: []
|
|
},
|
|
dropped_intent_segments: [],
|
|
detected_mode: input.addressDebug.detected_mode,
|
|
detected_mode_confidence: input.addressDebug.detected_mode_confidence,
|
|
query_shape: input.addressDebug.query_shape,
|
|
query_shape_confidence: input.addressDebug.query_shape_confidence,
|
|
detected_intent: input.addressDebug.detected_intent,
|
|
detected_intent_confidence: input.addressDebug.detected_intent_confidence,
|
|
extracted_filters: input.addressDebug.extracted_filters,
|
|
missing_required_filters: input.addressDebug.missing_required_filters,
|
|
selected_recipe: input.addressDebug.selected_recipe,
|
|
mcp_call_status_legacy: input.addressDebug.mcp_call_status_legacy,
|
|
account_scope_mode: input.addressDebug.account_scope_mode,
|
|
account_scope_fallback_applied: input.addressDebug.account_scope_fallback_applied,
|
|
anchor_type: input.addressDebug.anchor_type,
|
|
anchor_value_raw: input.addressDebug.anchor_value_raw,
|
|
anchor_value_resolved: input.addressDebug.anchor_value_resolved,
|
|
resolver_confidence: input.addressDebug.resolver_confidence,
|
|
ambiguity_count: input.addressDebug.ambiguity_count,
|
|
match_failure_stage: input.addressDebug.match_failure_stage,
|
|
match_failure_reason: input.addressDebug.match_failure_reason,
|
|
mcp_call_status: input.addressDebug.mcp_call_status,
|
|
rows_fetched: input.addressDebug.rows_fetched,
|
|
raw_rows_received: input.addressDebug.raw_rows_received,
|
|
rows_after_account_scope: input.addressDebug.rows_after_account_scope,
|
|
rows_after_recipe_filter: input.addressDebug.rows_after_recipe_filter,
|
|
rows_materialized: input.addressDebug.rows_materialized,
|
|
rows_matched: input.addressDebug.rows_matched,
|
|
raw_row_keys_sample: input.addressDebug.raw_row_keys_sample,
|
|
materialization_drop_reason: input.addressDebug.materialization_drop_reason,
|
|
account_token_raw: input.addressDebug.account_token_raw,
|
|
account_token_normalized: input.addressDebug.account_token_normalized,
|
|
account_scope_fields_checked: input.addressDebug.account_scope_fields_checked,
|
|
account_scope_match_strategy: input.addressDebug.account_scope_match_strategy,
|
|
account_scope_drop_reason: input.addressDebug.account_scope_drop_reason,
|
|
runtime_readiness: input.addressDebug.runtime_readiness,
|
|
limited_reason_category: input.addressDebug.limited_reason_category,
|
|
organization_candidates: input.addressDebug.organization_candidates ?? undefined,
|
|
response_type: input.addressDebug.response_type,
|
|
requested_result_mode: input.addressDebug.requested_result_mode ?? undefined,
|
|
result_mode: input.addressDebug.result_mode ?? undefined,
|
|
evidence_strength: input.addressDebug.evidence_strength ?? undefined,
|
|
balance_confirmed: typeof input.addressDebug.balance_confirmed === "boolean" ? input.addressDebug.balance_confirmed : undefined,
|
|
as_of_date_basis: input.addressDebug.as_of_date_basis ?? undefined,
|
|
capability_id: input.addressDebug.capability_id ?? undefined,
|
|
capability_layer: input.addressDebug.capability_layer ?? undefined,
|
|
capability_route_mode: input.addressDebug.capability_route_mode ?? undefined,
|
|
capability_route_enabled: typeof input.addressDebug.capability_route_enabled === "boolean"
|
|
? input.addressDebug.capability_route_enabled
|
|
: undefined,
|
|
capability_route_reason: input.addressDebug.capability_route_reason ?? undefined,
|
|
shadow_route_intent: input.addressDebug.shadow_route_intent ?? undefined,
|
|
shadow_route_selected_recipe: input.addressDebug.shadow_route_selected_recipe ?? undefined,
|
|
shadow_route_status: input.addressDebug.shadow_route_status ?? undefined,
|
|
route_expectation_status: input.addressDebug.route_expectation_status ?? undefined,
|
|
route_expectation_reason: input.addressDebug.route_expectation_reason ?? undefined,
|
|
route_expectation_expected_selected_recipes: input.addressDebug.route_expectation_expected_selected_recipes ?? undefined,
|
|
route_expectation_expected_requested_result_modes: input.addressDebug.route_expectation_expected_requested_result_modes ?? undefined,
|
|
route_expectation_expected_result_modes: input.addressDebug.route_expectation_expected_result_modes ?? undefined,
|
|
execution_lane: "address_query",
|
|
llm_decomposition_applied: Boolean(llmMeta?.applied),
|
|
llm_decomposition_attempted: Boolean(llmMeta?.attempted),
|
|
llm_provider_used: llmMeta?.provider ?? null,
|
|
llm_decomposition_trace_id: llmMeta?.traceId ?? null,
|
|
llm_decomposition_effective_message: llmMeta?.effectiveMessage ?? null,
|
|
llm_decomposition_reason: llmMeta?.reason ?? null,
|
|
llm_canonical_candidate_detected: Boolean(llmMeta?.llmCanonicalCandidateDetected),
|
|
llm_predecompose_contract: llmMeta?.predecomposeContract ?? null,
|
|
fallback_rule_hit: llmMeta?.fallbackRuleHit ?? null,
|
|
sanitized_user_message: llmMeta?.sanitizedUserMessage ?? null,
|
|
tool_gate_decision: llmMeta?.toolGateDecision ?? null,
|
|
tool_gate_reason: llmMeta?.toolGateReason ?? null,
|
|
orchestration_contract_v1: llmMeta?.orchestrationContract ?? null,
|
|
dialog_continuation_contract_v2: llmMeta?.dialogContinuationContract ?? null,
|
|
address_retry_audit: llmMeta?.addressRetryAudit ?? null,
|
|
answer_structure_v11: null,
|
|
investigation_state_snapshot: null,
|
|
normalized: null,
|
|
normalizer_output: llmMeta?.traceId
|
|
? {
|
|
trace_id: llmMeta.traceId,
|
|
prompt_version: "normalizer_v2_0_2",
|
|
applied: Boolean(llmMeta?.applied),
|
|
effective_message: llmMeta?.effectiveMessage ?? null
|
|
}
|
|
: null
|
|
};
|
|
}
|
|
function buildDeepAnalysisDebugPayload(input) {
|
|
const analysisContext = toAnalysisContext(input.runtimeAnalysisContext);
|
|
const answerContractStage4Audit = (0, assistantStage4AnswerContractAudit_1.buildStage4AnswerContractAuditV1)(input.assistantReply);
|
|
const debugPayload = {
|
|
trace_id: input.traceId,
|
|
prompt_version: input.promptVersion,
|
|
schema_version: input.schemaVersion,
|
|
fallback_type: input.fallbackType,
|
|
route_summary: input.routeSummary,
|
|
fragments: input.fragments,
|
|
requirements_extracted: input.requirementsExtracted,
|
|
coverage_report: input.coverageReport,
|
|
routes: input.routes,
|
|
retrieval_status: input.retrievalStatus,
|
|
retrieval_results: input.retrievalResults,
|
|
answer_grounding_check: input.groundingCheck,
|
|
dropped_intent_segments: input.droppedIntentSegments,
|
|
question_type_class: input.questionTypeClass,
|
|
company_anchors: input.companyAnchors,
|
|
analysis_context_applied: input.runtimeAnalysisContext.active,
|
|
analysis_context: analysisContext,
|
|
business_scope_raw: input.businessScopeResolution.business_scope_raw,
|
|
business_scope_resolved: input.businessScopeResolution.business_scope_resolved,
|
|
company_grounding_applied: input.businessScopeResolution.company_grounding_applied,
|
|
scope_resolution_reason: input.businessScopeResolution.scope_resolution_reason,
|
|
company_scope_resolution_reason: input.businessScopeResolution.scope_resolution_reason,
|
|
raw_time_anchor: input.temporalGuard.raw_time_anchor,
|
|
raw_time_scope: input.temporalGuard.raw_time_scope,
|
|
resolved_time_anchor: input.temporalGuard.resolved_time_anchor,
|
|
resolved_primary_period: input.temporalGuard.resolved_primary_period,
|
|
effective_primary_period: input.temporalGuard.effective_primary_period,
|
|
temporal_guard_input: input.temporalGuard.temporal_guard_input,
|
|
temporal_alignment_status: input.temporalGuard.temporal_alignment_status,
|
|
temporal_resolution_source: input.temporalGuard.temporal_resolution_source,
|
|
temporal_guard_basis: input.temporalGuard.temporal_guard_basis,
|
|
temporal_guard_applied: input.temporalGuard.temporal_guard_applied,
|
|
temporal_guard_outcome: input.temporalGuard.temporal_guard_outcome,
|
|
temporal_guard: input.temporalGuard,
|
|
raw_numeric_tokens: input.polarityAudit.raw_numeric_tokens,
|
|
classified_numeric_tokens: input.polarityAudit.classified_numeric_tokens,
|
|
rejected_as_non_accounts: input.polarityAudit.rejected_as_non_accounts,
|
|
resolved_account_anchors: input.polarityAudit.resolved_account_anchors,
|
|
domain_polarity_guard: input.polarityAudit,
|
|
claim_anchor_audit: input.claimAnchorAudit,
|
|
settlement_role: input.claimAnchorAudit.settlement_role ?? null,
|
|
settlement_role_resolution_reason: input.claimAnchorAudit.settlement_role_resolution_reason ?? [],
|
|
polarity_resolution_status: input.claimAnchorAudit.polarity_resolution_status ?? "not_applicable",
|
|
targeted_evidence_acquisition: input.targetedEvidenceAudit,
|
|
evidence_admissibility_gate: input.evidenceAdmissibilityGateAudit,
|
|
...(input.rbpLiveRouteAudit ? { rbp_live_route_audit: input.rbpLiveRouteAudit } : {}),
|
|
...(input.faLiveRouteAudit ? { fa_live_route_audit: input.faLiveRouteAudit } : {}),
|
|
eligibility_time_basis: input.groundedAnswerEligibilityGuard.eligibility_time_basis,
|
|
grounded_answer_eligibility_guard: input.groundedAnswerEligibilityGuard,
|
|
...(input.followupStateUsage ? { followup_state_usage: input.followupStateUsage } : {}),
|
|
problem_centric_answer_applied: input.compositionDebug.problem_centric_answer_applied ?? false,
|
|
problem_units_used_count: input.compositionDebug.problem_units_used_count ?? 0,
|
|
problem_answer_mode: input.compositionDebug.problem_answer_mode ?? "stage1_policy_v11",
|
|
...(Array.isArray(input.compositionDebug.problem_unit_ids_used) && input.compositionDebug.problem_unit_ids_used.length > 0
|
|
? {
|
|
problem_unit_ids_used: input.compositionDebug.problem_unit_ids_used
|
|
}
|
|
: {}),
|
|
address_llm_predecompose_attempted: Boolean(input.addressRuntimeMetaForDeep?.attempted),
|
|
address_llm_predecompose_applied: Boolean(input.addressRuntimeMetaForDeep?.applied),
|
|
address_llm_predecompose_reason: input.addressRuntimeMetaForDeep?.reason ?? null,
|
|
address_llm_predecompose_provider: input.addressRuntimeMetaForDeep?.provider ?? null,
|
|
address_fallback_rule_hit: input.addressRuntimeMetaForDeep?.fallbackRuleHit ?? null,
|
|
address_tool_gate_decision: input.addressRuntimeMetaForDeep?.toolGateDecision ?? null,
|
|
address_tool_gate_reason: input.addressRuntimeMetaForDeep?.toolGateReason ?? null,
|
|
address_llm_predecompose_contract: input.addressRuntimeMetaForDeep?.predecomposeContract ?? null,
|
|
address_semantic_extraction_contract: input.addressRuntimeMetaForDeep?.semanticExtractionContract ?? null,
|
|
orchestration_contract_v1: input.addressRuntimeMetaForDeep?.orchestrationContract ?? null,
|
|
assistant_outcome_class_v1: input.outcomeClassV1,
|
|
assistant_orchestration_contracts_v1: input.assistantOrchestrationContractsV1,
|
|
answer_contract_stage4_v1: answerContractStage4Audit,
|
|
answer_structure_v11: input.answerStructureV11,
|
|
investigation_state_snapshot: input.investigationStateSnapshot,
|
|
normalized: input.normalizedPayload
|
|
};
|
|
const debugWithRuntimeContracts = (0, assistantRuntimeContractResolver_1.attachAssistantRuntimeContractShadow)(debugPayload, {
|
|
addressRuntimeMeta: input.addressRuntimeMetaForDeep,
|
|
groundingStatus: input.groundingCheck.status
|
|
});
|
|
const debugWithTruthAnswerPolicy = (0, assistantTruthAnswerPolicyRuntimeAdapter_1.attachAssistantTruthAnswerPolicy)(debugWithRuntimeContracts, {
|
|
addressRuntimeMeta: input.addressRuntimeMetaForDeep,
|
|
groundingStatus: input.groundingCheck.status,
|
|
coverageReport: input.coverageReport,
|
|
replyType: "deep_analysis"
|
|
});
|
|
const debugWithStateTransition = (0, assistantStateTransitionRuntimeAdapter_1.attachAssistantStateTransition)(debugWithTruthAnswerPolicy, {
|
|
addressRuntimeMeta: input.addressRuntimeMetaForDeep,
|
|
groundingStatus: input.groundingCheck.status,
|
|
coverageReport: input.coverageReport,
|
|
replyType: "deep_analysis"
|
|
});
|
|
return (0, assistantCapabilityRuntimeBindingAdapter_1.attachAssistantCapabilityRuntimeBinding)(debugWithStateTransition, {
|
|
addressRuntimeMeta: input.addressRuntimeMetaForDeep,
|
|
groundingStatus: input.groundingCheck.status,
|
|
coverageReport: input.coverageReport,
|
|
replyType: "deep_analysis"
|
|
});
|
|
}
|