refactor: 精简发给模型的上下文、隐藏接口原始报错,合并重复的删除逻辑

- 发给模型的对话只留最近 20 条,除最后一条 AI 回复外旧回复的代码块换成占位文字,
  对话越长越省 token,也不会超出上下文长度
- 学生看到的 AI 报错只显示超时 / 繁忙 / 出错(状态码),完整错误写日志;
  客户端自己断开导致的中止不再记错误
- 管理员查询对话必须带 task_id 或 user_id,不再一次查出全站所有对话
- “已评分或获奖不能删”和“删除一轮对话”合并到 services/cascade.ts,补上删除一轮对话的测试

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
xuyueandClaude Opus 5.5 committed 2026-10-26 22:26:37 +08:00
1 parent 325474bdb7
commit ffdfbc2513
8 files changed
+122 -35

No files matched your search

+5 -2
View File
@@ -7,6 +7,7 @@ import {
parseGuidanceResponse,
streamChat,
streamGuidance,
userFacingError,
type ChatMessage,
} from "./services/llm"
@@ -122,7 +123,8 @@ async function handlePrompt(ws: WS, data: any) {
try {
full = await streamToClient(ws, streamChat(history, model, ws.data.abort.signal))
} catch (e) {
send(ws, { type: "error", content: `AI 服务出错:${e instanceof Error ? e.message : e}` })
// 客户端自己断开导致的中止不算出错
if (!ws.data.closed) send(ws, { type: "error", content: userFacingError(e) })
return
}
if (ws.data.closed) return
@@ -161,7 +163,8 @@ async function handleGuidance(ws: WS, data: any) {
} catch (e) {
// 这条提问没有回复,留在上下文里会出现连续两条用户消息
ws.data.guidanceHistory.pop()
send(ws, { type: "error", content: `AI 服务出错:${e instanceof Error ? e.message : e}` })
// 客户端自己断开导致的中止不算出错
if (!ws.data.closed) send(ws, { type: "error", content: userFacingError(e) })
return
}
if (ws.data.closed) return