feat(ai写作): 自带大纲/会商及研究模板等前后端改动
提交工作区中 AI 写作(表单/时间线/历史/上下文/流式 hook/类型)、 研究模板配置页、lead_agent、researcher/graph/state 及 gateway/config 的进行中改动。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d2c76100f2
commit
e9c8d1cea2
18 files changed
+287
-50
No files matched your search
+35
-3
@@ -62,6 +62,17 @@ async def pause_material_confirm(state: AIWritingState) -> dict:
|
||||
approved_ids = set(user_input.get("approvedMaterialIds") or [m["id"] for m in pkg["materials"]])
|
||||
filtered = [m for m in pkg["materials"] if m["id"] in approved_ids]
|
||||
updated_pkg = {**pkg, "materials": filtered}
|
||||
# 用户自带大纲:researcher 已在「搜集素材」阶段解析大纲并归类素材 → 跳过大纲生成步,
|
||||
# 仅把被用户取消勾选的素材从各章节 material_ids 里剔除,直接进入大纲确认。
|
||||
prebuilt = state.get("current_outline")
|
||||
if prebuilt and (state.get("user_outline_raw") or "").strip():
|
||||
return {
|
||||
"material_package": updated_pkg,
|
||||
"current_outline": _prune_outline_material_ids(prebuilt, approved_ids),
|
||||
"last_user_intervention": user_input,
|
||||
"status": "awaiting_outline_confirm",
|
||||
"progress_events": [{"type": "resumed", "agent_name": "系统", "message": "已采用你提供的大纲并归类素材,请确认大纲"}],
|
||||
}
|
||||
return {
|
||||
"material_package": updated_pkg,
|
||||
"last_user_intervention": user_input,
|
||||
@@ -90,6 +101,21 @@ async def pause_material_confirm(state: AIWritingState) -> dict:
|
||||
}
|
||||
|
||||
|
||||
def _prune_outline_material_ids(outline: dict, approved_ids: set) -> dict:
|
||||
"""把大纲各章节 material_ids 里、用户在素材确认卡取消勾选的素材编号剔除掉。
|
||||
|
||||
用户自带大纲时素材归类发生在「搜集素材」阶段(researcher),早于素材确认;
|
||||
用户在确认卡里去掉某些素材后,用这个函数把对应编号从大纲剔除,保持一致。
|
||||
"""
|
||||
if not outline:
|
||||
return outline
|
||||
sections = []
|
||||
for s in outline.get("sections", []):
|
||||
kept = [mid for mid in (s.get("material_ids") or []) if mid in approved_ids]
|
||||
sections.append({**s, "material_ids": kept})
|
||||
return {**outline, "sections": sections}
|
||||
|
||||
|
||||
def _normalize_outline(outline: dict) -> dict:
|
||||
"""将前端回传的 camelCase 大纲统一为后端 snake_case 格式。"""
|
||||
if not outline:
|
||||
@@ -318,7 +344,13 @@ def after_researcher(state: AIWritingState) -> str:
|
||||
|
||||
|
||||
def after_material_pause(state: AIWritingState) -> str:
|
||||
return "researcher" if state["status"] == "researching" else "writer_outline"
|
||||
status = state["status"]
|
||||
if status == "researching":
|
||||
return "researcher"
|
||||
# 用户自带大纲:researcher 已在搜集阶段整理好大纲 → 跳过 writer_outline 生成步,直接确认大纲。
|
||||
if status == "awaiting_outline_confirm":
|
||||
return "pause_outline"
|
||||
return "writer_outline"
|
||||
|
||||
|
||||
def after_outline_pause(state: AIWritingState) -> str:
|
||||
@@ -396,9 +428,9 @@ def make_ai_writing_graph(config=None):
|
||||
g.set_entry_point("intent_parser")
|
||||
g.add_edge("intent_parser", "researcher")
|
||||
g.add_conditional_edges("researcher", after_researcher,
|
||||
{"pause_material": "pause_material", "writer_draft": "writer_draft"})
|
||||
{"pause_material": "pause_material", "writer_draft": "writer_draft", "writer_outline": "writer_outline"})
|
||||
g.add_conditional_edges("pause_material", after_material_pause,
|
||||
{"researcher": "researcher", "writer_outline": "writer_outline"})
|
||||
{"researcher": "researcher", "writer_outline": "writer_outline", "pause_outline": "pause_outline"})
|
||||
g.add_edge("writer_outline", "pause_outline")
|
||||
g.add_conditional_edges("pause_outline", after_outline_pause,
|
||||
{"writer_outline": "writer_outline", "writer_draft": "writer_draft"})
|
||||
|
||||
Reference in new issue
Block a user