69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import { buildAssistantAnswerStructureV11 } from "./assistantAnswerPackageBuilder";
|
|
import type {
|
|
AssistantConversationItem,
|
|
AssistantDebugPayload,
|
|
AssistantReplyType,
|
|
AnswerGroundingCheck,
|
|
RequirementCoverageReport,
|
|
UnifiedRetrievalResult
|
|
} from "../types/assistant";
|
|
import type { AnswerStructureV11 } from "../types/stage1Contracts";
|
|
|
|
export interface DeepAnswerArtifacts {
|
|
safeAssistantReply: string;
|
|
answerStructureV11: AnswerStructureV11 | null;
|
|
}
|
|
|
|
function stripTechnicalTail(text: string): string {
|
|
return String(text ?? "")
|
|
.replace(/(?:^|\n)\s*#{0,6}\s*(?:debug_payload_json|technical_breakdown_json)\b[\s\S]*$/gi, "")
|
|
.replace(/\b(?:debug_payload_json|technical_breakdown_json)\b[\s\S]*$/gi, "")
|
|
.trim();
|
|
}
|
|
|
|
export function buildDeepAnswerArtifacts(input: {
|
|
safeAssistantReplyBase: string;
|
|
featureContractsV11: boolean;
|
|
featureAnswerPolicyV11: boolean;
|
|
compositionAnswerStructureV11: AnswerStructureV11 | null | undefined;
|
|
coverageReport: RequirementCoverageReport;
|
|
groundingCheck: AnswerGroundingCheck;
|
|
retrievalResults: UnifiedRetrievalResult[];
|
|
}): DeepAnswerArtifacts {
|
|
const safeAssistantReply = stripTechnicalTail(input.safeAssistantReplyBase);
|
|
const answerStructureV11 = input.featureContractsV11
|
|
? input.featureAnswerPolicyV11 && input.compositionAnswerStructureV11
|
|
? input.compositionAnswerStructureV11
|
|
: buildAssistantAnswerStructureV11({
|
|
assistantReply: safeAssistantReply,
|
|
coverageReport: input.coverageReport,
|
|
groundingCheck: input.groundingCheck,
|
|
retrievalResults: input.retrievalResults
|
|
})
|
|
: null;
|
|
return {
|
|
safeAssistantReply,
|
|
answerStructureV11
|
|
};
|
|
}
|
|
|
|
export function buildAssistantConversationItem(input: {
|
|
messageId: string;
|
|
sessionId: string;
|
|
text: string;
|
|
replyType: AssistantReplyType;
|
|
traceId: string | null;
|
|
debug: AssistantDebugPayload;
|
|
}): AssistantConversationItem {
|
|
return {
|
|
message_id: input.messageId,
|
|
session_id: input.sessionId,
|
|
role: "assistant",
|
|
text: input.text,
|
|
reply_type: input.replyType,
|
|
created_at: new Date().toISOString(),
|
|
trace_id: input.traceId,
|
|
debug: input.debug
|
|
};
|
|
}
|