fix(consult): drop traces, budget checkpoints, silent summary inherit
BUG-729: dropped history rounds leave an omission marker in the model-visible summary slot. BUG-730: checkpoint threshold is 0.4 of historyBudgetChars (128k still 16,000). BUG-731: session_full new chat copies owned context_summary on the server; clients send only continued_from_session_id.
This commit is contained in:
@@ -330,6 +330,7 @@ export async function POST(request: Request) {
|
||||
{ status: 503 },
|
||||
);
|
||||
}
|
||||
const sessionContextWindow = sessionModel.contextWindow;
|
||||
|
||||
if (parsed.data.entrypoint === "birth_time_rectification") {
|
||||
return NextResponse.json(
|
||||
@@ -353,7 +354,7 @@ export async function POST(request: Request) {
|
||||
// Client `history` stays in the request schema for old bundles and is not read.
|
||||
const contextSummary = parseSessionContextSummary(chatSession.context_summary);
|
||||
const historyWindow = consultationHistoryWindow(chatSession.messages, contextSummary, {
|
||||
contextWindow: sessionModel.contextWindow,
|
||||
contextWindow: sessionContextWindow,
|
||||
});
|
||||
const storedHistory = historyWindow.tail;
|
||||
const userControlledPrompt = [
|
||||
@@ -596,6 +597,7 @@ export async function POST(request: Request) {
|
||||
await checkpointSessionContextSummary({
|
||||
messages: sessionRow.messages,
|
||||
summary: sessionRow.context_summary,
|
||||
contextWindow: sessionContextWindow,
|
||||
generateText: (prompt, signal) => generateSessionContextSummaryText(summaryModel, prompt, signal),
|
||||
update: async (summary, seenUpdatedAt) => {
|
||||
let query = supabase.from("chat_sessions")
|
||||
@@ -875,6 +877,7 @@ export async function POST(request: Request) {
|
||||
instruction: modeInstruction,
|
||||
extra: generalDailyContextPrompt(generalDailyContext),
|
||||
summaryText: historyWindow.summaryText,
|
||||
droppedCount: historyWindow.droppedCount,
|
||||
question: resolvedQuestion.modelQuestion,
|
||||
}),
|
||||
},
|
||||
@@ -1271,6 +1274,7 @@ export async function POST(request: Request) {
|
||||
instruction: generalNoMinuteInstruction(Boolean(generalDailyContext)),
|
||||
extra: generalDailyContextPrompt(generalDailyContext),
|
||||
summaryText: historyWindow.summaryText,
|
||||
droppedCount: historyWindow.droppedCount,
|
||||
question: resolvedQuestion.modelQuestion,
|
||||
}),
|
||||
},
|
||||
@@ -1355,6 +1359,7 @@ export async function POST(request: Request) {
|
||||
name,
|
||||
instruction: "先用 3–6 句口语直接回答下面的问题,不要加标题;形状为一句结论、2–3 条短要点(每条完整句子、不超过 30 字)、一句下一步,总量不超过 400 字;然后再按 skill Level 2 骨架写:原始结构、六步宫位、Yoga 表、时机、综合、文末技法审计表,最后才是现代生活。骨架不可省略。星盘事实只使用系统里已经注入的计算结果,不要复述内部字段、JSON 或再跑一遍咨询流程。",
|
||||
summaryText: historyWindow.summaryText,
|
||||
droppedCount: historyWindow.droppedCount,
|
||||
question: resolvedQuestion.modelQuestion,
|
||||
}),
|
||||
},
|
||||
@@ -1379,6 +1384,7 @@ export async function POST(request: Request) {
|
||||
name,
|
||||
instruction: "先用 3–6 句口语直接回答下面的问题,不要加标题;形状为一句结论、2–3 条短要点(每条完整句子、不超过 30 字)、一句下一步,总量不超过 400 字;然后再按 skill Level 2 骨架写:原始结构、六步宫位、Yoga 表、时机、综合、文末技法审计表,最后才是现代生活。骨架不可省略。星盘事实只使用系统里已经注入的计算结果,不要复述内部字段、JSON 或再跑一遍咨询流程。",
|
||||
summaryText: historyWindow.summaryText,
|
||||
droppedCount: historyWindow.droppedCount,
|
||||
question: resolvedQuestion.modelQuestion,
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { chatSessionCreateSchema, ChatSessionBodyTooLargeError, readChatSessionJson } from "@/lib/chat-session-write-contract";
|
||||
import {
|
||||
chatSessionCreateInsertRow,
|
||||
chatSessionCreateSchema,
|
||||
ChatSessionBodyTooLargeError,
|
||||
readChatSessionJson,
|
||||
} from "@/lib/chat-session-write-contract";
|
||||
import { consumeUserRequestRateLimit } from "@/lib/request-rate-limit";
|
||||
import { resolveInheritedContextSummary } from "@/lib/session-context-summary";
|
||||
import { isSupabaseConfigurationError } from "@/lib/supabase/config";
|
||||
import { createServerSupabaseClient } from "@/lib/supabase/server";
|
||||
import {
|
||||
@@ -94,13 +100,28 @@ export async function POST(request: Request) {
|
||||
}
|
||||
const parsed = chatSessionCreateSchema.safeParse(await readChatSessionJson(request));
|
||||
if (!parsed.success) return NextResponse.json({ error: "聊天记录格式不正确" }, { status: 400 });
|
||||
const { id, updated_at: _ignoredClientClock, ...values } = parsed.data;
|
||||
const { error } = await supabase.from("chat_sessions").insert({
|
||||
id,
|
||||
user_id: user.id,
|
||||
...values,
|
||||
updated_at: new Date().toISOString(),
|
||||
const { id, updated_at: _ignoredClientClock, continued_from_session_id: continuedFromSessionId, ...values } = parsed.data;
|
||||
const inheritedSummary = await resolveInheritedContextSummary({
|
||||
continuedFromSessionId,
|
||||
loadOwnedSummary: async (sourceId) => {
|
||||
const { data } = await supabase
|
||||
.from("chat_sessions")
|
||||
.select("context_summary")
|
||||
.eq("id", sourceId)
|
||||
.eq("user_id", user.id)
|
||||
.maybeSingle();
|
||||
return data?.context_summary ?? null;
|
||||
},
|
||||
});
|
||||
const { error } = await supabase.from("chat_sessions").insert(
|
||||
chatSessionCreateInsertRow({
|
||||
id,
|
||||
userId: user.id,
|
||||
values,
|
||||
inheritedSummary,
|
||||
updatedAt: new Date().toISOString(),
|
||||
}),
|
||||
);
|
||||
if (error) return NextResponse.json({ error: "聊天记录暂时无法同步" }, { status: 500 });
|
||||
return NextResponse.json({ ok: true }, { status: 201 });
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user