feat(rectification): submit varga-resolution implementation for review
Review-only snapshot for BUG-1115 through BUG-1117; not merge-ready. New opening and append-turn PostgreSQL permission failures remain blocked. Persisted joint replay has zero completed questions; segment ordering remains off by default. The existing offline replay JSON is retained stale and unchanged after a denied overwrite, including its CRLF line endings. Browser/provider validation and final serial gates remain pending. No deployment, role permission changes, or staging/main push. Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
committed by
Jesse_Chen
co-authored by
Claude Code
parent
75166802d8
commit
66f087b588
@@ -10,7 +10,7 @@ import {
|
||||
awaitTurnExitBeforeResponse,
|
||||
finalizeSuccessfulTurnExit,
|
||||
} from "@/lib/rectification-agentic/v9/turn-exit";
|
||||
import type { RectificationAgentTurnState } from "@/lib/rectification-agentic/v9/agent-route-support";
|
||||
import { completedMessageResponse, type RectificationAgentTurnState } from "@/lib/rectification-agentic/v9/agent-route-support";
|
||||
import { resolveRectificationAgentRequest } from "@/lib/rectification-agentic/v9/agent-route-request";
|
||||
import { handleRectificationStructuredChoice } from "@/lib/rectification-agentic/v9/agent-route-structured-choice";
|
||||
import {
|
||||
@@ -66,6 +66,15 @@ export async function POST(request: Request) {
|
||||
const frozen = await refuseWhenAccountDeletionPending(userId);
|
||||
if (frozen) return frozen;
|
||||
|
||||
if (action === "opening") {
|
||||
const consistency = await finalizeSuccessfulTurnExit({
|
||||
accounting: accounting as never, userId, caseId, action, segmentOpening: true,
|
||||
});
|
||||
if (consistency?.segmentConsistency) {
|
||||
return completedMessageResponse(consistency.text, context.requestId, caseId, consistency.turnId);
|
||||
}
|
||||
}
|
||||
|
||||
const declaredWindowReply = await replyToDeclaredBirthWindow(context);
|
||||
if (declaredWindowReply) return declaredWindowReply;
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ function errorResponse(error: unknown) {
|
||||
["agentic_rectification_candidate_expired", 409, "候选结果已过期,请重新比较"],
|
||||
["agentic_rectification_candidate_selection_blocked", 409, "当前还不能采用候选"],
|
||||
["agentic_rectification_candidate_state_inconsistent", 409, "候选状态已更新,请刷新后重试"],
|
||||
["agentic_rectification_segment_state_inconsistent", 409, "盘型证据已更新,请刷新后重试"],
|
||||
["agentic_rectification_candidate_time_not_allowed", 409, "该时间不在当前候选内"],
|
||||
["agentic_rectification_candidate_already_selected", 409, "该时间已采用"],
|
||||
["agentic_rectification_candidate_superseded", 409, "已有更新的候选结果"],
|
||||
@@ -139,15 +140,16 @@ export async function POST(request: Request, context: RouteContext) {
|
||||
representativeTime: decision.representativeTime,
|
||||
});
|
||||
|
||||
const segmentAdoption = Boolean(decision.segmentSummary?.adoption_minute);
|
||||
const { data, error } = await accounting.rpc(
|
||||
"accept_agentic_rectification_candidate_for_case_v2",
|
||||
segmentAdoption ? "accept_agentic_rectification_segment_for_case_v1" : "accept_agentic_rectification_candidate_for_case_v2",
|
||||
{
|
||||
p_user_id: user.id,
|
||||
p_case_id: caseId,
|
||||
p_result_id: parsed.data.resultId,
|
||||
p_candidate_id: parsed.data.candidateId,
|
||||
p_request_id: parsed.data.requestId,
|
||||
...(credibleRange ? { p_credible_range: credibleRange } : {}),
|
||||
...(!segmentAdoption && credibleRange ? { p_credible_range: credibleRange } : {}),
|
||||
},
|
||||
);
|
||||
if (error) throw new RectificationToolServiceError(error.message);
|
||||
|
||||
@@ -10,6 +10,8 @@ import {
|
||||
openRectificationCase,
|
||||
} from "@/lib/rectification-agentic/v9/case-service";
|
||||
import { parseOpenRectificationCaseRequest } from "@/lib/rectification-agentic/v9/open-request";
|
||||
import { prepareCaseSegmentChecks } from "@/lib/rectification-agentic/v9/segment-checks";
|
||||
import { resolveRectificationProductDomain } from "@/lib/rectification-agentic/v9/product-domain";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
@@ -29,7 +31,8 @@ function serviceErrorResponse(error: unknown) {
|
||||
/**
|
||||
* POST /api/rectification/cases/open
|
||||
*
|
||||
* Browser sends only { intent, requestId } (+ sessionId for intent=session).
|
||||
* Browser sends { intent, requestId } (+ sessionId for intent=session, or
|
||||
* sourceSessionId for a consultation handoff). Domain is read server-side.
|
||||
* The server derives the user from the session, normalizes the profile and
|
||||
* creates for homepage/new or restores the exact requested session. Retries are idempotent.
|
||||
*/
|
||||
@@ -70,7 +73,11 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await openRectificationCase(accounting, user.id, parsed);
|
||||
const domain = await resolveRectificationProductDomain(supabase, user.id, parsed);
|
||||
const response = await openRectificationCase(accounting, user.id, parsed, domain);
|
||||
if (response.shouldStartOpening) {
|
||||
await prepareCaseSegmentChecks({ accounting: accounting as never, userId: user.id, caseId: response.caseId });
|
||||
}
|
||||
return NextResponse.json(response);
|
||||
} catch (error) {
|
||||
return serviceErrorResponse(error);
|
||||
|
||||
Reference in New Issue
Block a user