refactor(frontend): 四生成 hook 结束后额外返回产物(AC-3 留痕前置)

useRefine.refine/recommunicate→RefineVersion|null、useContinue.generate→string|null、
useChapterRewrite.send→RewriteVersion|null、useGenerator.generate→GeneratorArtifact|null。
向后兼容(既有调用忽略返回值不受影响);各 hook 成功用例补返回值断言。
面板据此 if(artifact) 才 append,空候选/错误路径不留痕。
This commit is contained in:
Yaojia Wang
2026-07-09 17:15:49 +02:00
parent ddf7fa061a
commit 59f2f60a7e
8 changed files with 66 additions and 25 deletions

View File

@@ -13,8 +13,8 @@ export type ContinueStatus = "idle" | "generating" | "ready" | "error";
export interface UseContinue {
status: ContinueStatus;
candidates: string[];
// 生成一条续写候选累加不覆盖chapterNo 指定承接哪一章。
generate: (projectId: string, chapterNo: number) => Promise<void>;
// 生成一条续写候选累加不覆盖chapterNo 指定承接哪一章。返回本条候选文本,空/失败返回 null。
generate: (projectId: string, chapterNo: number) => Promise<string | null>;
reset: () => void;
}
@@ -45,19 +45,21 @@ export function useContinue(): UseContinue {
if (error || !data) {
setStatus("error");
toast(generationErrorMessage(error), "error");
return;
return null;
}
const text = extractText(data.preview).trim();
if (text.length === 0) {
setStatus("ready");
toast("本次未生成有效续写,请再试一次。", "info");
return;
return null;
}
setCandidates((prev) => [...prev, text]);
setStatus("ready");
return text;
} catch {
setStatus("error");
toast("续写请求异常,请检查网络。", "error");
return null;
}
},
[toast],