fix(rectification): render adoption carrier on deterministic choice path
This commit is contained in:
@@ -5,7 +5,6 @@ import {
|
||||
evidenceLedgerFingerprint,
|
||||
loadV9CaseCompute,
|
||||
loadV9CaseDossier,
|
||||
loadV9TurnReceipt,
|
||||
persistV9DeterministicTurn,
|
||||
RectificationToolServiceError,
|
||||
transitionV9CaseStatus,
|
||||
@@ -686,14 +685,10 @@ export async function POST(request: Request) {
|
||||
);
|
||||
}
|
||||
try {
|
||||
const receipt = await loadV9TurnReceipt(accounting as never, userId, caseId, result.turnId);
|
||||
const exit = await ensureNonTerminalTurnExit({
|
||||
accounting: accounting as never,
|
||||
userId,
|
||||
caseId,
|
||||
adoptCarrierReady: Boolean(receipt?.toolActivities.some((activity) => (
|
||||
activity.tool === "rectification-offer-candidates" && activity.status === "completed"
|
||||
))),
|
||||
});
|
||||
idleHostNarration = exit.hostNarration ?? idleHostNarration;
|
||||
} catch (error) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import { choiceCardFromCaseDossier, decideFromDossier, overlayPublicDecision } f
|
||||
import { projectCurrentQuestion } from "@/lib/rectification-agentic/v9/turn-decision";
|
||||
import { previousInferenceFromReceipt } from "@/lib/rectification-agentic/v9/inference-adapter";
|
||||
import { publicDecisionFields } from "@/lib/rectification-agentic/core/rectification-decision";
|
||||
import { slimDecisionReceipt } from "@/lib/rectification-agentic/v9/case-receipt-projection";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
@@ -49,7 +50,9 @@ export async function GET(request: Request, context: RouteContext) {
|
||||
if (!z.string().uuid().safeParse(caseId).success) {
|
||||
return NextResponse.json({ error: "请求内容不正确", code: "invalid_case_id" }, { status: 400 });
|
||||
}
|
||||
const sessionId = new URL(request.url).searchParams.get("sessionId") ?? "";
|
||||
const searchParams = new URL(request.url).searchParams;
|
||||
const sessionId = searchParams.get("sessionId") ?? "";
|
||||
const fullDetail = searchParams.get("detail") === "full";
|
||||
|
||||
try {
|
||||
const dossier = await loadV9CaseDossier(accounting, user.id, caseId);
|
||||
@@ -66,7 +69,7 @@ export async function GET(request: Request, context: RouteContext) {
|
||||
}
|
||||
}),
|
||||
);
|
||||
return NextResponse.json(dossierResponse(dossier, receipts, skillIdentity));
|
||||
return NextResponse.json(dossierResponse(dossier, receipts, skillIdentity, { fullDetail }));
|
||||
} catch (error) {
|
||||
if (error instanceof RectificationToolServiceError) {
|
||||
const message = error.message;
|
||||
@@ -85,6 +88,7 @@ function dossierResponse(
|
||||
dossier: V9CaseDossier,
|
||||
receipts: Array<Awaited<ReturnType<typeof loadV9TurnReceipt>>>,
|
||||
skillIdentity: Awaited<ReturnType<typeof loadV9CaseSkillIdentityStatus>>,
|
||||
options: { fullDetail?: boolean } = {},
|
||||
) {
|
||||
const decision = decideFromDossier(dossier, {
|
||||
currentEvidenceFingerprint: evidenceLedgerFingerprint(dossier.evidence),
|
||||
@@ -115,13 +119,30 @@ function dossierResponse(
|
||||
receipt: turnReceipt(turn.id, receipts),
|
||||
})),
|
||||
evidence: dossier.evidence,
|
||||
latest_result: dossier.latestResult ? overlayPublicDecision(dossier.latestResult, decision) : null,
|
||||
latest_result: dossier.latestResult
|
||||
? publicLatestResult(dossier.latestResult, decision, dossier, options.fullDetail === true)
|
||||
: null,
|
||||
interview: publicDecisionFields(decision),
|
||||
current_question: projectCurrentQuestion(dossier.conversationSummary.activeFocus),
|
||||
choice_card: choiceCardFromCaseDossier(dossier),
|
||||
};
|
||||
}
|
||||
|
||||
function publicLatestResult(
|
||||
latest: V9CaseDossier["latestResult"],
|
||||
decision: ReturnType<typeof decideFromDossier>,
|
||||
dossier: V9CaseDossier,
|
||||
fullDetail: boolean,
|
||||
) {
|
||||
if (!latest) return null;
|
||||
const projected = overlayPublicDecision(latest, decision);
|
||||
if (fullDetail || !projected.decisionReceipt) return projected;
|
||||
return {
|
||||
...projected,
|
||||
decisionReceipt: slimDecisionReceipt(projected.decisionReceipt, dossier),
|
||||
};
|
||||
}
|
||||
|
||||
function turnReceipt(
|
||||
turnId: string,
|
||||
receipts: Array<Awaited<ReturnType<typeof loadV9TurnReceipt>>>,
|
||||
|
||||
@@ -1020,7 +1020,6 @@ export function RectificationAgenticChat(props: RectificationAgenticChatProps) {
|
||||
&& !message.failed
|
||||
&& Boolean(message.text)
|
||||
));
|
||||
const offeredSelectionOnce = messages.some(turnOfferedSelection);
|
||||
const answeredQuestionIds = new Set(
|
||||
messages.flatMap((message) => message.choiceAttachment
|
||||
? [message.choiceAttachment.card.question_id]
|
||||
@@ -1049,10 +1048,11 @@ export function RectificationAgenticChat(props: RectificationAgenticChatProps) {
|
||||
}, [showLiveChoiceCard, updateFollowState]);
|
||||
const showSelectionCards = Boolean(
|
||||
candidateResult?.selectionAllowed
|
||||
&& offeredSelectionOnce
|
||||
&& candidateResult?.canAdopt
|
||||
&& latestSettledAssistant
|
||||
&& !showLiveChoiceCard
|
||||
&& !busy
|
||||
&& !readonly
|
||||
&& regeneratingMessageKey === null,
|
||||
);
|
||||
const selectionCardMessageKey = showSelectionCards && latestSettledAssistant
|
||||
|
||||
@@ -729,6 +729,14 @@ ${nextInterview.hostNarration}`
|
||||
nextInterviewPersisted = true;
|
||||
}
|
||||
}
|
||||
const adoptionNarration = nextAction.type === "offer_provisional_range" && nextAction.can_adopt
|
||||
? `${nonConvergingRangeNarration({
|
||||
credibleRange: nextAction.credible_range,
|
||||
representativeTime: nextAction.representative_time,
|
||||
})} 可以从下面的时间里选一个采用。`
|
||||
: null;
|
||||
if (adoptionNarration) hostNarration = adoptionNarration;
|
||||
|
||||
if (
|
||||
command.deferFollowup !== true
|
||||
&& (nextInterviewPersisted || !shouldContinueAfterStructuredChoice(nextAction, { nextInterviewPersisted }))
|
||||
@@ -745,7 +753,7 @@ ${nextInterview.hostNarration}`
|
||||
}
|
||||
}
|
||||
|
||||
const narration = (nextInterviewPersisted ? hostNarration : null)
|
||||
const narration = (adoptionNarration || nextInterviewPersisted ? hostNarration : null)
|
||||
|| (persisted.narration && persisted.narration.trim())
|
||||
|| hostNarration
|
||||
|| composeChoiceNarration({
|
||||
@@ -783,7 +791,6 @@ export async function ensureNonTerminalTurnExit(input: {
|
||||
accounting: AccountingClient;
|
||||
userId: string;
|
||||
caseId: string;
|
||||
adoptCarrierReady: boolean;
|
||||
}): Promise<{ persisted: boolean; choiceReady: boolean; hostNarration: string | null }> {
|
||||
const dossier = await loadV9CaseDossier(input.accounting, input.userId, input.caseId);
|
||||
if (projectCurrentQuestion(dossier.conversationSummary.activeFocus)) {
|
||||
@@ -801,7 +808,7 @@ export async function ensureNonTerminalTurnExit(input: {
|
||||
dossier.case.acceptedTime
|
||||
|| dossier.case.confirmedTime
|
||||
|| decision.completionStatus === "provisional_range_user_stopped"
|
||||
|| (decision.canAdopt && input.adoptCarrierReady)
|
||||
|| decision.canAdopt
|
||||
) {
|
||||
return { persisted: false, choiceReady: false, hostNarration: null };
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { previousInferenceFromReceipt } from "./inference-adapter";
|
||||
import type { V9CaseDossier } from "./tool-service";
|
||||
|
||||
export function slimDecisionReceipt(
|
||||
receipt: Readonly<Record<string, unknown>>,
|
||||
dossier: Pick<V9CaseDossier, "case" | "conversationSummary" | "latestResult">,
|
||||
): Readonly<Record<string, unknown>> {
|
||||
const activeTimes = new Set<string>();
|
||||
const inference = previousInferenceFromReceipt(receipt);
|
||||
const activeInferenceCandidates = inference?.candidates.filter((candidate) => candidate.status === "active") ?? [];
|
||||
for (const candidate of activeInferenceCandidates.length > 0
|
||||
? activeInferenceCandidates
|
||||
: dossier.latestResult?.candidates ?? []) {
|
||||
activeTimes.add(candidate.time);
|
||||
}
|
||||
for (const value of [inference?.representative_time, dossier.latestResult?.representativeTime, dossier.latestResult?.selectedTime]) {
|
||||
if (typeof value === "string" && value.trim()) activeTimes.add(value.slice(0, 5));
|
||||
}
|
||||
const focusSchema = dossier.conversationSummary.activeFocus?.expectedAnswerSchema ?? {};
|
||||
const currentProbeIds = new Set(
|
||||
[focusSchema.probe_id, focusSchema.semantic_key, focusSchema.candidate_split_hash]
|
||||
.filter((value): value is string => typeof value === "string" && value.trim().length > 0),
|
||||
);
|
||||
const result = { ...receipt };
|
||||
const tables = receipt.house_tables_by_time;
|
||||
if (tables && typeof tables === "object" && !Array.isArray(tables)) {
|
||||
result.house_tables_by_time = Object.fromEntries(
|
||||
Object.entries(tables as Record<string, unknown>)
|
||||
.filter(([time]) => activeTimes.has(time.slice(0, 5))),
|
||||
);
|
||||
}
|
||||
if (receipt.house_table && typeof receipt.house_table === "object" && !Array.isArray(receipt.house_table)) {
|
||||
const table = receipt.house_table as Record<string, unknown>;
|
||||
if (typeof table.time === "string" && !activeTimes.has(table.time.slice(0, 5))) {
|
||||
delete result.house_table;
|
||||
}
|
||||
}
|
||||
for (const key of [
|
||||
"discriminating_event_probes",
|
||||
"event_clarification_probes",
|
||||
"evidence_collection_probes",
|
||||
]) {
|
||||
const probes = result[key];
|
||||
if (!Array.isArray(probes)) continue;
|
||||
result[key] = probes.filter((probe) => {
|
||||
if (!probe || typeof probe !== "object" || Array.isArray(probe)) return false;
|
||||
const row = probe as Record<string, unknown>;
|
||||
return [row.id, row.probe_id, row.semantic_key, row.candidate_split_hash]
|
||||
.some((value) => typeof value === "string" && currentProbeIds.has(value));
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -53,6 +53,7 @@ export type RectificationCandidateResult = Readonly<{
|
||||
candidates: readonly RectificationCandidate[];
|
||||
overallConfidence: "low" | "medium" | "high";
|
||||
selectionAllowed: boolean;
|
||||
canAdopt: boolean;
|
||||
confirmationAllowed: boolean;
|
||||
representativeTime: string | null;
|
||||
selectedTime: string | null;
|
||||
@@ -267,6 +268,7 @@ export function parseRectificationCandidateResult(value: unknown): Rectification
|
||||
? snapshot.overallConfidence
|
||||
: "low",
|
||||
selectionAllowed: snapshot.selectionAllowed === true || snapshot.selection_allowed === true,
|
||||
canAdopt: snapshot.canAdopt === true || snapshot.can_adopt === true,
|
||||
confirmationAllowed: snapshot.confirmationAllowed === true,
|
||||
representativeTime,
|
||||
selectedTime,
|
||||
|
||||
Reference in New Issue
Block a user