feat: 删除提问时级联删除其回答,并移除回答上的删除按钮
- 删除按钮只保留在用户提问气泡上;AI 回答不再单独提供删除
- 后端 DELETE /messages/{id} 改为按整轮删除:从提问删到下一条提问之前,
返回实际删除的 deleted_ids,保持 checkpoint 合法(无孤立工具结果/回答)
- 前端隐藏后端返回的整批 id,删除后即时消失
- 更新删除相关中英文案
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
5d12616211
commit
1f2b1e3b8a
7 files changed
+73
-46
No files matched your search
@@ -805,11 +805,13 @@ export function useDeleteThread() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a single message (a user question or an assistant answer) from a
|
||||
* thread. Hits the Gateway endpoint that filters the message out of the latest
|
||||
* checkpoint. The live `useStream` cache is not auto-refreshed by this call —
|
||||
* callers hide the deleted id locally (see `MessageList`) so the removal shows
|
||||
* immediately; a reload then reads the persisted, already-trimmed state.
|
||||
* Delete a conversation turn (a user question together with its answer) from a
|
||||
* thread. Hits the Gateway endpoint that removes the question and every
|
||||
* following message up to the next question from the latest checkpoint, and
|
||||
* returns the ids that were actually removed. The live `useStream` cache is not
|
||||
* auto-refreshed by this call — callers hide the returned ids locally (see
|
||||
* `MessageList`) so the removal shows immediately; a reload then reads the
|
||||
* persisted, already-trimmed state.
|
||||
*/
|
||||
export function useDeleteMessage() {
|
||||
return useMutation({
|
||||
@@ -819,7 +821,7 @@ export function useDeleteMessage() {
|
||||
}: {
|
||||
threadId: string;
|
||||
messageId: string;
|
||||
}) => {
|
||||
}): Promise<string[]> => {
|
||||
const response = await apiFetch(
|
||||
`${getBackendBaseURL()}/api/threads/${encodeURIComponent(
|
||||
threadId,
|
||||
@@ -835,6 +837,12 @@ export function useDeleteMessage() {
|
||||
.catch(() => ({ detail: "删除消息失败。" }));
|
||||
throw new Error(error.detail ?? "删除消息失败。");
|
||||
}
|
||||
|
||||
const body = (await response.json().catch(() => ({}))) as {
|
||||
deleted_ids?: string[];
|
||||
};
|
||||
// Fall back to the requested id so the caller can always hide something.
|
||||
return body.deleted_ids?.length ? body.deleted_ids : [messageId];
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user