ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Этап 4.5: добавлен аудит контракта Stage 4 в debug/log и закрыт расширенный quality-loop
This commit is contained in:
@@ -23,6 +23,7 @@ import type {
|
||||
GroundedAnswerEligibilityAudit,
|
||||
TemporalGuardAudit
|
||||
} from "./assistantRuntimeGuards";
|
||||
import { buildStage4AnswerContractAuditV1 } from "./assistantStage4AnswerContractAudit";
|
||||
|
||||
type RetrievalStatusItem = AssistantDebugPayload["retrieval_status"][number];
|
||||
|
||||
@@ -75,6 +76,7 @@ export interface DeepAnalysisDebugPayloadInput {
|
||||
outcomeClassV1: AssistantOutcomeClassV1;
|
||||
assistantOrchestrationContractsV1: AssistantContractsBundleV1["assistantOrchestrationContractsV1"];
|
||||
answerStructureV11: AnswerStructureV11 | null;
|
||||
assistantReply: string;
|
||||
investigationStateSnapshot: InvestigationStateWithProblemUnits | null;
|
||||
normalizedPayload: NormalizeResponsePayload["normalized"];
|
||||
}
|
||||
@@ -94,6 +96,7 @@ function toAnalysisContext(input: DeepAnalysisDebugPayloadInput["runtimeAnalysis
|
||||
|
||||
export function buildDeepAnalysisDebugPayload(input: DeepAnalysisDebugPayloadInput): AssistantDebugPayload {
|
||||
const analysisContext = toAnalysisContext(input.runtimeAnalysisContext);
|
||||
const answerContractStage4Audit = buildStage4AnswerContractAuditV1(input.assistantReply);
|
||||
return {
|
||||
trace_id: input.traceId,
|
||||
prompt_version: input.promptVersion,
|
||||
@@ -165,6 +168,7 @@ export function buildDeepAnalysisDebugPayload(input: DeepAnalysisDebugPayloadInp
|
||||
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
|
||||
|
||||
@@ -216,6 +216,7 @@ export function assembleAssistantDeepTurnPackaging(input: AssistantDeepTurnPacka
|
||||
outcomeClassV1: contractsBundleV1.outcomeClassV1,
|
||||
assistantOrchestrationContractsV1: contractsBundleV1.assistantOrchestrationContractsV1,
|
||||
answerStructureV11: deepAnswerArtifacts.answerStructureV11,
|
||||
assistantReply: deepAnswerArtifacts.safeAssistantReply,
|
||||
investigationStateSnapshot: input.investigationStateSnapshot,
|
||||
normalizedPayload: normalizedPayload
|
||||
});
|
||||
|
||||
@@ -28,6 +28,7 @@ import type {
|
||||
GroundedAnswerEligibilityAudit,
|
||||
TemporalGuardAudit
|
||||
} from "./assistantRuntimeGuards";
|
||||
import { buildStage4AnswerContractAuditV1 } from "./assistantStage4AnswerContractAudit";
|
||||
|
||||
export interface DeepAnalysisMessageLogDetailsInput {
|
||||
sessionId: string;
|
||||
@@ -110,6 +111,7 @@ export type DeepAnalysisLogDetails = Record<string, unknown>;
|
||||
|
||||
export function buildDeepAnalysisProcessedLogDetails(input: DeepAnalysisMessageLogDetailsInput): DeepAnalysisLogDetails {
|
||||
const analysisContext = toAnalysisContext(input.runtimeAnalysisContext);
|
||||
const answerContractStage4Audit = buildStage4AnswerContractAuditV1(input.assistantReply);
|
||||
return {
|
||||
session_id: input.sessionId,
|
||||
message_id: input.messageId,
|
||||
@@ -180,6 +182,7 @@ export function buildDeepAnalysisProcessedLogDetails(input: DeepAnalysisMessageL
|
||||
: {}),
|
||||
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,
|
||||
fallback_type: input.compositionDebug.fallback_type,
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
export interface Stage4AnswerContractAuditV1 {
|
||||
schema_version: "stage4_answer_contract_audit_v1";
|
||||
stage4_blocks_expected: string[];
|
||||
stage4_blocks_present: string[];
|
||||
stage4_blocks_missing: string[];
|
||||
legacy_blocks_present: string[];
|
||||
is_stage4_shape: boolean;
|
||||
}
|
||||
|
||||
const STAGE4_EXPECTED_BLOCKS = [
|
||||
"Коротко",
|
||||
"Что именно проверено",
|
||||
"Что найдено",
|
||||
"Что пока не доказано"
|
||||
] as const;
|
||||
|
||||
const STAGE4_NEXT_STEP_BLOCKS = ["Что проверить первым", "Что могу сделать сейчас"] as const;
|
||||
|
||||
const LEGACY_BLOCKS = [
|
||||
"Что сломано",
|
||||
"Почему это похоже на проблему",
|
||||
"На чем это основано",
|
||||
"Ограничения"
|
||||
] as const;
|
||||
|
||||
function hasBlock(reply: string, title: string): boolean {
|
||||
return reply.includes(`${title}:`);
|
||||
}
|
||||
|
||||
export function buildStage4AnswerContractAuditV1(assistantReply: string): Stage4AnswerContractAuditV1 {
|
||||
const reply = String(assistantReply ?? "");
|
||||
const expected: string[] = [...STAGE4_EXPECTED_BLOCKS, "Что проверить первым/Что могу сделать сейчас"];
|
||||
|
||||
const present: string[] = STAGE4_EXPECTED_BLOCKS.filter((title) => hasBlock(reply, title));
|
||||
const hasPrimaryNextStep = STAGE4_NEXT_STEP_BLOCKS.some((title) => hasBlock(reply, title));
|
||||
if (hasPrimaryNextStep) {
|
||||
present.push("Что проверить первым/Что могу сделать сейчас");
|
||||
}
|
||||
|
||||
const missing = expected.filter((title) => !present.includes(title));
|
||||
const legacyPresent = LEGACY_BLOCKS.filter((title) => hasBlock(reply, title));
|
||||
|
||||
return {
|
||||
schema_version: "stage4_answer_contract_audit_v1",
|
||||
stage4_blocks_expected: expected,
|
||||
stage4_blocks_present: present,
|
||||
stage4_blocks_missing: missing,
|
||||
legacy_blocks_present: legacyPresent,
|
||||
is_stage4_shape: missing.length === 0 && legacyPresent.length === 0
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user