feat(ai写作): 历史记录可继续未完成的会话(从checkpoint续跑)

历史列表里 in_progress/draft_ready/review_ready 记录加绿色▶️「继续未完成」按钮
(点标题亦可);done/error/background 不可继续。多 worker 安全——与4个确认卡同机制,
全基于共享 checkpoint(gateway GET /threads/{id}/state + /history 读,任意 worker)。

链路:continueWriting(sessionId) → closeHistory + 设活跃 sessionId → useStream
fetchStateHistory 拉该 thread checkpoint 进 stream.values → host rehydrate effect
(continueTargetRef 守卫,每 thread 一次)用 buildRehydrateSnapshot 重建已完成阶段;
status=awaiting_* → 显示确认卡等用户操作,否则 submit({command:{}}) 从 checkpoint
续跑当前阶段。重新加回 buildRehydrateSnapshot + rehydrate action。

入口在侧栏 WritingHistoryItem。刷新=重置不受影响(这是显式点击,非自动重连)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
董宏凯andClaude Opus 4.8 committed 2026-06-27 13:12:47 +08:00
1 parent e889cc25cf
commit c11307aa67
3 files changed
+135 -10

No files matched your search

@@ -12,6 +12,7 @@ import {
Newspaper,
PanelLeftClose,
Pencil,
Play,
Plus,
RefreshCw,
Search,
@@ -109,12 +110,17 @@ const WRITING_STATUS_PILL: Record<string, { label: string; className: string; sp
error: { label: "出错", className: "text-rose-500" },
};
/** 可「继续未完成」的状态:有可恢复的 checkpoint(mid-stage 或停在确认点)。done/error 终态、
* background 自有进度弹窗,都不算。 */
const RESUMABLE_STATUSES = new Set(["in_progress", "draft_ready", "review_ready"]);
/** 单条历史记录项 —— 样式参考多智能体会商的 HistoryDropdown 列表项(圆角卡片 + 状态药丸 + 操作按钮)。 */
function WritingHistoryItem({
session,
isCurrent,
onSelect,
onShowProgress,
onContinue,
onDelete,
onRename,
}: {
@@ -122,6 +128,8 @@ function WritingHistoryItem({
isCurrent: boolean;
onSelect: () => void;
onShowProgress?: () => void;
/** 继续这条未完成的会话(从 checkpoint 续跑当前阶段 / 显示确认卡)。 */
onContinue?: () => void;
onDelete: () => void;
onRename: (title: string) => void;
}) {
@@ -129,8 +137,10 @@ function WritingHistoryItem({
const [value, setValue] = useState(session.title);
const inputRef = useRef<HTMLInputElement>(null);
const isBackground = session.status === "background";
// 「挂起中」点击看进度(流程图弹窗),其余打开历史回看。
const open = isBackground && onShowProgress ? onShowProgress : onSelect;
const canContinue = !!onContinue && RESUMABLE_STATUSES.has(session.status);
// 行/标题主点击:未完成→继续续跑;挂起中→看进度弹窗;其余(完成/出错)→只读历史回看。
const primary = isBackground && onShowProgress ? onShowProgress : (canContinue ? onContinue! : onSelect);
const primaryTitle = isBackground ? "查看进度" : canContinue ? "继续未完成" : "打开历史";
const pill = WRITING_STATUS_PILL[session.status] ?? { label: session.status, className: "text-slate-400" };
useEffect(() => {
@@ -168,9 +178,9 @@ function WritingHistoryItem({
) : (
<button
type="button"
onClick={open}
onClick={primary}
className="block w-full text-left"
title={isBackground ? "查看进度" : "打开历史"}
title={primaryTitle}
>
<span className="line-clamp-2 text-[11.5px] font-semibold leading-snug text-slate-800">
{session.title}
@@ -190,10 +200,20 @@ function WritingHistoryItem({
{!renaming && (
<div className="flex shrink-0 items-center gap-0.5">
{canContinue && (
<button
type="button"
onClick={onContinue}
title="继续未完成"
className="rounded p-1 text-emerald-500 transition hover:bg-emerald-50 hover:text-emerald-600"
>
<Play className="size-3.5 fill-current" />
</button>
)}
<button
type="button"
onClick={open}
title={isBackground ? "查看进度" : "打开"}
onClick={isBackground && onShowProgress ? onShowProgress : onSelect}
title={isBackground ? "查看进度" : "只读查看"}
className="rounded p-1 text-slate-500 transition hover:bg-slate-100 hover:text-primary"
>
<Eye className="size-3.5" />
@@ -238,7 +258,7 @@ export function ResearchSidebar({
}) {
const navigate = useNavigate();
const { templates, refresh } = useResearchTemplates();
const { startWriting } = useAIWriting();
const { startWriting, continueWriting } = useAIWriting();
const {
notebooks,
isLoading: notebooksLoading,
@@ -266,7 +286,7 @@ export function ResearchSidebar({
rename: renameSession,
remove: removeSession,
} = useAIWritingSessions();
const { openHistory, historySession } = useAIWritingHistory();
const { openHistory, closeHistory, historySession } = useAIWritingHistory();
// 进入/返回写作配置页时刷新一次历史(本侧栏仅在 idle 态挂载,故等同每次回到表单刷新)。
useEffect(() => {
@@ -276,6 +296,11 @@ export function ResearchSidebar({
const handleSelectHistory = (session: AIWritingSessionSummary) => {
void openHistory(session);
};
// 「继续未完成」:退出只读历史态(若在),把该会话设为活跃并从 checkpoint 续跑。
const handleContinue = (session: AIWritingSessionSummary) => {
closeHistory();
continueWriting(session.id);
};
// 「挂起中」记录:交给右侧面板打开进度流程图弹窗(沿用面板已有的 window 事件解耦模式,
// 与 ai-writing:open-session 一致),本侧栏不直接持有弹窗状态。
const handleShowProgress = (session: AIWritingSessionSummary) => {
@@ -592,6 +617,7 @@ export function ResearchSidebar({
isCurrent={s.id === (historySession?.id ?? null)}
onSelect={() => handleSelectHistory(s)}
onShowProgress={() => handleShowProgress(s)}
onContinue={() => handleContinue(s)}
onDelete={() => removeSession(s.id)}
onRename={(title) => renameSession(s.id, title)}
/>