feat: 导图改用知识碎片素材并输出结构化报告草稿

This commit is contained in:
2026-10-09 19:12:04 +08:00
parent 1c3168277d
commit e359e58ff2
4 changed files with 113 additions and 30 deletions
+40 -3
View File
@@ -385,10 +385,46 @@ function callOptionsFor(type: TaskType): { temperature: number; maxTokens: numbe
}
/** 把模型原文转成结构化结果 */
/**
* 解析结构化的报告草稿。
*
* 报告是结构化的(会话摘要 / 预期达成判断 / 自由总结),但 LLM 不一定老实返回 JSON:
* 这里对「带代码块围栏」「返回了纯文本」两种情况都做降级,把整段文本当作自由总结,
* 保证用户至少拿到一份可编辑的草稿,而不是一个报错。
*/
export function parseReportDraft(raw: string, model = ""): {
sessionSummary: string;
expectationVerdict: string;
freeSummary: string;
model: string;
} {
const text = raw.trim();
const jsonText = text.replace(/^```(?:json)?\s*/, "").replace(/\s*```$/, "");
try {
const parsed = JSON.parse(jsonText) as Record<string, unknown>;
const pick = (key: string): string => {
const value = parsed[key];
return typeof value === "string" ? value : "";
};
const draft = {
sessionSummary: pick("sessionSummary"),
expectationVerdict: pick("expectationVerdict"),
freeSummary: pick("freeSummary"),
model,
};
if (draft.sessionSummary || draft.expectationVerdict || draft.freeSummary) {
return draft;
}
} catch {
// 不是 JSON:按纯文本降级处理
}
return { sessionSummary: "", expectationVerdict: "", freeSummary: text, model };
}
export function parseResult(type: TaskType, raw: string, model = ""): unknown {
const text = raw.trim();
if (type === "aggregate-report") {
return { report: text, model };
return parseReportDraft(text, model);
}
if (type === "generate-mind-map") {
return { outline: text, model };
@@ -409,11 +445,12 @@ export function buildMessages(task: TaskRecord): ChatMessage[] {
);
}
case "generate-mind-map": {
const reports = p.reports as string[] | undefined;
// 素材为「该任务名下的知识碎片」(按内容归属取),不再用按会话产生的报告
const fragments = p.fragments as string[] | undefined;
return generateMindMapPrompt(
p.taskName as string,
(p.taskDescription as string) ?? "",
reports ?? [],
fragments ?? [],
);
}
case "compare-recall": {