feat(rectification): remove the rectification regenerate button and endpoint (BUG-1056)
T2 of TASK-rectification-grounding-20260927 (product decision P1). The rectification 「重试(重新生成)」 was a blind agent.generate rewrite that persisted unchecked text (invented range / fit rate reproduced). Removed: the regenerate route, regenerate-turn.ts, the regeneration agent and its read-only tool set, the client regenerate action/state and the regenerating/canRegenerate props. ChatMessageActions renders the regenerate button only when onRegenerate is passed; ordinary consultation is unchanged. The DB function regenerate_agentic_rectification_turn is kept (AGENTS §7.6, retire in a later round). DESIGN.md / VOICE.md updated; source-contract tests follow with 原值/新值/原因 notes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017eEAG8HD3mm8gsKXgk8uU8
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5a8084494b
commit
84eb23152a
@@ -1,159 +0,0 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { regenerateV9AssistantTurn } from "@/lib/rectification-agentic/v9/regenerate-turn";
|
||||
import {
|
||||
loadV9CaseSkillIdentity,
|
||||
RectificationToolServiceError,
|
||||
} from "@/lib/rectification-agentic/v9/tool-service";
|
||||
import { resolveExactSkillPackage } from "@/lib/skill-package-registry";
|
||||
import { resolveSessionLanguageModel } from "@/lib/model-catalog";
|
||||
import { jsonForSupabaseSetupFailure } from "@/lib/api/service-unavailable";
|
||||
import { createAdminSupabaseClient } from "@/lib/supabase/admin";
|
||||
import { withRectificationRequestCache } from "@/lib/rectification-agentic/v9/request-cache";
|
||||
import { createServerSupabaseClient } from "@/lib/supabase/server";
|
||||
import { getRectificationV9RegenerationAgent } from "@/mastra/agentic-rectification";
|
||||
import { logRectificationDeliveryTurn } from "@/lib/rectification-agentic/v9/delivery-turn-guard";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const maxDuration = 240;
|
||||
|
||||
type RouteContext = { params: Promise<{ caseId: string; turnId: string }> };
|
||||
|
||||
const regenerateSchema = z.object({
|
||||
sessionId: z.string().uuid(),
|
||||
requestId: z.string().uuid(),
|
||||
}).strict();
|
||||
|
||||
function errorResponse(error: unknown) {
|
||||
const code = error instanceof RectificationToolServiceError
|
||||
? error.code
|
||||
: error instanceof Error
|
||||
? error.message
|
||||
: String(error);
|
||||
const known = [
|
||||
["agentic_rectification_case_not_found", 404, "校正记录不存在或无权访问", "case_not_found"],
|
||||
["agentic_rectification_turn_not_found", 404, "这条回答不存在或无法重新生成", "turn_not_found"],
|
||||
["agentic_rectification_case_session_mismatch", 409, "校正记录与会话绑定不一致", "case_session_mismatch"],
|
||||
["agentic_rectification_case_terminal", 409, "该校正已结束,只能查看历史", "case_terminal"],
|
||||
["agentic_rectification_turn_not_latest", 409, "只能重新生成最近一条回答", "turn_not_latest"],
|
||||
["agentic_rectification_turn_not_completed", 409, "这条回答尚未完成", "turn_not_completed"],
|
||||
["agentic_rectification_regeneration_request_conflict", 409, "重新生成请求已用于其他回答", "request_conflict"],
|
||||
["agentic_rectification_legacy_skill_identity_unverifiable", 409, "该校正绑定的是无法核验的历史 Skill,请先采用当前注册版本", "skill_identity_unverifiable"],
|
||||
["agentic_rectification_skill_identity_missing", 409, "该校正绑定的 Skill 版本不可用,请联系支持人员", "skill_identity_missing"],
|
||||
["agentic_rectification_skill_identity_mismatch", 409, "校正记录与 Skill 版本绑定不一致", "skill_identity_mismatch"],
|
||||
["agentic_rectification_invalid_skill_identity", 400, "Skill 版本身份不正确", "invalid_skill_identity"],
|
||||
] as const;
|
||||
for (const [needle, status, message, publicCode] of known) {
|
||||
if (code.includes(needle)) {
|
||||
return NextResponse.json({ error: message, code: publicCode }, { status });
|
||||
}
|
||||
}
|
||||
return NextResponse.json(
|
||||
{ error: "暂时无法重新生成回答", code: "regeneration_failed" },
|
||||
{ status: 503 },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Free, read-only reply regeneration. The model receives only the bound Skill
|
||||
* and rectification-read-case tool. The database then replaces the latest
|
||||
* completed Assistant text in place; no turn is appended and billing is never
|
||||
* invoked by this route.
|
||||
*/
|
||||
export async function POST(request: Request, context: RouteContext) {
|
||||
let supabase;
|
||||
let accounting;
|
||||
try {
|
||||
supabase = await createServerSupabaseClient();
|
||||
accounting = withRectificationRequestCache(createAdminSupabaseClient());
|
||||
} catch (error) {
|
||||
return jsonForSupabaseSetupFailure(error, "POST /api/rectification/cases/[caseId]/turns/[turnId]/regenerate");
|
||||
}
|
||||
|
||||
const {
|
||||
data: { user },
|
||||
error: authError,
|
||||
} = await supabase.auth.getUser();
|
||||
if (authError || !user) {
|
||||
return NextResponse.json({ error: "请先登录" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { caseId, turnId } = await context.params;
|
||||
if (!z.string().uuid().safeParse(caseId).success || !z.string().uuid().safeParse(turnId).success) {
|
||||
return NextResponse.json({ error: "请求内容不正确", code: "invalid_reference" }, { status: 400 });
|
||||
}
|
||||
const parsed = regenerateSchema.safeParse(await request.json().catch(() => null));
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json({ error: "请求内容不正确", code: "invalid_regeneration_request" }, { status: 400 });
|
||||
}
|
||||
|
||||
const { data: chatSession, error: chatSessionError } = await supabase
|
||||
.from("chat_sessions")
|
||||
.select("id,session_type,model_id,model_config_version,agentic_rectification_case_id")
|
||||
.eq("id", parsed.data.sessionId)
|
||||
.eq("user_id", user.id)
|
||||
.maybeSingle();
|
||||
if (chatSessionError) {
|
||||
return NextResponse.json({ error: "暂时无法读取会话" }, { status: 503 });
|
||||
}
|
||||
if (!chatSession || chatSession.session_type !== "birth_time_rectification") {
|
||||
return NextResponse.json({ error: "生时校正会话不存在", code: "session_not_found" }, { status: 404 });
|
||||
}
|
||||
if (chatSession.agentic_rectification_case_id !== caseId) {
|
||||
return NextResponse.json({ error: "校正记录与会话绑定不一致", code: "case_session_mismatch" }, { status: 409 });
|
||||
}
|
||||
|
||||
const selectedModel = await resolveSessionLanguageModel(
|
||||
chatSession.model_id,
|
||||
chatSession.model_config_version,
|
||||
);
|
||||
if (!selectedModel) {
|
||||
return NextResponse.json(
|
||||
{ error: "模型暂不可用", message: "请选择其他模型后再试,本次不会扣除点数。" },
|
||||
{ status: 409 },
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const boundIdentity = await loadV9CaseSkillIdentity(accounting, user.id, caseId);
|
||||
const skillPackage = resolveExactSkillPackage(
|
||||
boundIdentity.name,
|
||||
boundIdentity.version,
|
||||
boundIdentity.sha256,
|
||||
);
|
||||
if (skillPackage.sourceCommit !== boundIdentity.sourceCommit) {
|
||||
throw new RectificationToolServiceError("agentic_rectification_skill_identity_mismatch");
|
||||
}
|
||||
const agent = getRectificationV9RegenerationAgent(selectedModel, {
|
||||
userId: user.id,
|
||||
caseId,
|
||||
turnId,
|
||||
accounting,
|
||||
}, skillPackage);
|
||||
logRectificationDeliveryTurn({
|
||||
trigger: "regenerate",
|
||||
caseId,
|
||||
resultId: turnId,
|
||||
terminalNote: false,
|
||||
});
|
||||
const result = await regenerateV9AssistantTurn({
|
||||
userId: user.id,
|
||||
caseId,
|
||||
sessionId: parsed.data.sessionId,
|
||||
turnId,
|
||||
requestId: parsed.data.requestId,
|
||||
accounting,
|
||||
agent,
|
||||
skillPackage,
|
||||
signal: request.signal,
|
||||
});
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
turnId: result.turnId,
|
||||
assistantMessage: result.assistantMessage,
|
||||
idempotent: result.idempotent,
|
||||
});
|
||||
} catch (error) {
|
||||
return errorResponse(error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user