From 0089af94d3671aab78649367d34d8220c183a6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=87=AF?= Date: Fri, 26 Jun 2026 22:13:19 +0800 Subject: [PATCH 1/6] =?UTF-8?q?fix(ai=E5=86=99=E4=BD=9C):=20=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E5=86=85=E7=BD=91=E7=9B=B4=E8=BF=9E=E6=A3=80=E7=B4=A2?= =?UTF-8?q?(=E7=9F=A5=E8=AF=86=E5=BA=93=E6=A3=80=E7=B4=A2)=E7=A9=BA?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E5=9B=9E=E9=80=80=E9=BB=98=E8=AE=A4=E7=AB=AF?= =?UTF-8?q?=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit knowledge_base 检索类型遇到空 intranet_search_url 会短路报「未配置」、返回 0 素材,导致「内网直连检索不能用」。旧版 get_search_provider(search_provider= intranet) 在空地址时由 IntranetSearchProvider 回退内置默认内网端点,所以不配 地址也能直连。本次去掉该短路,空地址原样下传由 provider 回退默认端点,恢复旧逻辑。 - researcher.py: knowledge_base 分支无条件构造 IntranetSearchProvider - test_ai_writing_knowledge_base.py: 空地址用例改为断言回退默认端点仍出素材 - backend CLAUDE.md: 检索类型段说明更新 Co-Authored-By: Claude Opus 4.8 (1M context) --- offline-backend-20260512/backend/CLAUDE.md | 2 +- .../agents/ai_writing/nodes/researcher.py | 100 ++++++++---------- .../tests/test_ai_writing_knowledge_base.py | 12 ++- 3 files changed, 56 insertions(+), 58 deletions(-) diff --git a/offline-backend-20260512/backend/CLAUDE.md b/offline-backend-20260512/backend/CLAUDE.md index fcbb3651..a6f364e5 100644 --- a/offline-backend-20260512/backend/CLAUDE.md +++ b/offline-backend-20260512/backend/CLAUDE.md @@ -273,7 +273,7 @@ The AI-writing graph (`packages/harness/deerflow/agents/ai_writing/`) has four s Seeding mirrors the roundtable pattern: verified `config.yaml` + `SOUL.md` ship in `app/gateway/routers/_ai_writing_seed_assets//`; `_ai_writing_seed.py::ensure_ai_writing_functional_agents()` copies them to `.deer-flow/agents/` when missing (never overwrites local edits), called from the startup lifespan (before `_sync_legacy_agents`, so the agents appear in `/api/agents` on first boot) and self-heals from `GET /api/ai-writing/sessions` + `GET /api/ai-writing/article-types`. Tests: `tests/test_ai_writing_seed.py`, `tests/test_ai_writing_agent_runner.py`. -**Skill-driven retrieval (检索类型).** `material_source` has three values: `general` (通用检索, default), `knowledge_base` (知识库检索), and `notebook` (我的空间); legacy `skill` is normalized to `general` by the researcher node. **`knowledge_base` 直连内网 ES 接口** — it bypasses skill orchestration entirely and calls `IntranetSearchProvider` over `ai_writing.intranet_search_url` (concurrent over the generated keywords; `intranet_knowledge_base`/`intranet_search_timeout` apply); an unconfigured url → no materials + a `skill_error` notice. This is the "弱模型识别不了技能" escape hatch — the old no-skill retrieval path restored as an explicit option (weak models like deepseek-chat often fail to invoke configured skills). Tests: `tests/test_ai_writing_knowledge_base.py`. General retrieval is orchestrated from the **skills configured on the `ai-writing-researcher` agent** (`config.yaml → skills`, editable from the agent management page): the built-in `knowledge-base-search` skill (知识库检索) runs the native keyword fan-out web/intranet search (the old default path), while any other configured skill searches with a `description`-targeted query; skills run in configured order with early-stop at `max_materials`, and an empty/unresolvable skills config falls back to the built-in knowledge search so retrieval always works. The skill itself is seeded from `_ai_writing_seed_assets/skills/knowledge-base-search/SKILL.md` into `skills/public/` (never overwrites), and a pre-existing researcher `config.yaml` lacking the `skills` key is patched in place with the default (explicit `skills: []` is respected). **PAUSE-1 input append flow**: when the user types natural language into the material-confirm input (`re_search`/legacy `enable_skill_search` + `user_query`), the node matches the most relevant configured skill via `SkillPicker(candidates=…)` (skipped when only one skill is configured), searches with the user's words, and **appends** the new materials to the existing package (URL-dedup, original order preserved, no LLM re-rank/truncation, 100-item hard cap). **Skill-failure fault tolerance**: a configured skill that times out / raises / has all its keyword searches fail (vs. legitimately returning 0 results) no longer just silently moves on — the researcher node emits a `skill_search_step` of type `skill_error` (carrying the error `reason`), and if the configured skills collected **no** new materials at all it runs a `fallback` pass over other available skills (`_fallback_candidate_skills`: the built-in `knowledge-base-search` native path first, then other enabled catalog skills not yet tried) instead of erroring out. The frontend `SkillStepsCard` renders `skill_error` (rose) and `fallback` (amber) so the timeline shows "技能报错 → 改用其他技能搜集". Tests: `tests/test_ai_writing_material_source.py`. +**Skill-driven retrieval (检索类型).** `material_source` has three values: `general` (通用检索, default), `knowledge_base` (知识库检索), and `notebook` (我的空间); legacy `skill` is normalized to `general` by the researcher node. **`knowledge_base` 直连内网 ES 接口(= 旧版「内网直连检索」)** — it bypasses skill orchestration entirely and calls `IntranetSearchProvider` over `ai_writing.intranet_search_url` (concurrent over the generated keywords; `intranet_knowledge_base`/`intranet_search_timeout` apply). **An empty/unconfigured `intranet_search_url` does NOT disable it** — the empty string is passed straight to `IntranetSearchProvider`, which falls back to its built-in default endpoint (`intranet_stub._DEFAULT_ENDPOINT`), exactly like the legacy `get_search_provider(search_provider=intranet)` path. So 内网直连检索 works out of the box without configuring an address (configure `intranet_search_url` only to point at a different endpoint). This is the "弱模型识别不了技能" escape hatch — the old no-skill retrieval path restored as an explicit option (weak models like deepseek-chat often fail to invoke configured skills). Tests: `tests/test_ai_writing_knowledge_base.py`. General retrieval is orchestrated from the **skills configured on the `ai-writing-researcher` agent** (`config.yaml → skills`, editable from the agent management page): the built-in `knowledge-base-search` skill (知识库检索) runs the native keyword fan-out web/intranet search (the old default path), while any other configured skill searches with a `description`-targeted query; skills run in configured order with early-stop at `max_materials`, and an empty/unresolvable skills config falls back to the built-in knowledge search so retrieval always works. The skill itself is seeded from `_ai_writing_seed_assets/skills/knowledge-base-search/SKILL.md` into `skills/public/` (never overwrites), and a pre-existing researcher `config.yaml` lacking the `skills` key is patched in place with the default (explicit `skills: []` is respected). **PAUSE-1 input append flow**: when the user types natural language into the material-confirm input (`re_search`/legacy `enable_skill_search` + `user_query`), the node matches the most relevant configured skill via `SkillPicker(candidates=…)` (skipped when only one skill is configured), searches with the user's words, and **appends** the new materials to the existing package (URL-dedup, original order preserved, no LLM re-rank/truncation, 100-item hard cap). **Skill-failure fault tolerance**: a configured skill that times out / raises / has all its keyword searches fail (vs. legitimately returning 0 results) no longer just silently moves on — the researcher node emits a `skill_search_step` of type `skill_error` (carrying the error `reason`), and if the configured skills collected **no** new materials at all it runs a `fallback` pass over other available skills (`_fallback_candidate_skills`: the built-in `knowledge-base-search` native path first, then other enabled catalog skills not yet tried) instead of erroring out. The frontend `SkillStepsCard` renders `skill_error` (rose) and `fallback` (amber) so the timeline shows "技能报错 → 改用其他技能搜集". Tests: `tests/test_ai_writing_material_source.py`. **Skill-call timeout** is hardcoded **300s (5 min)** — `researcher.py` `_SKILL_SEARCH_TIMEOUT_SECONDS` (per-skill wrapper) and `_skill_agent.py` `_REAL_AGENT_TIMEOUT_SECONDS` (whole real-agent skill run). The intranet ES fallback (`IntranetSearchProvider`) gets a longer **600s (10 min)** default (`intranet_stub.py`; overridable via `ai_writing.intranet_search_timeout`) — that interface is the slow one, so our own fallback timeout is generous to avoid being blamed for "检不出". diff --git a/offline-backend-20260512/backend/packages/harness/deerflow/agents/ai_writing/nodes/researcher.py b/offline-backend-20260512/backend/packages/harness/deerflow/agents/ai_writing/nodes/researcher.py index 92ba3692..acfbe067 100644 --- a/offline-backend-20260512/backend/packages/harness/deerflow/agents/ai_writing/nodes/researcher.py +++ b/offline-backend-20260512/backend/packages/harness/deerflow/agents/ai_writing/nodes/researcher.py @@ -5,9 +5,10 @@ config.yaml 配置的技能顺序编排检索。内置「知识库检索」技能 (knowledge-base-search)走原生 web/intranet 关键词并发检索;其它技能用 其 description 生成定向 query 后调真实 provider 检索。 - - ``knowledge_base``(知识库检索):**直连内网知识库 ES 接口** - (``ai_writing.intranet_search_url`` 配的 ``IntranetSearchProvider``), - 不编排任何技能、也不跑通用 provider。未配置接口地址时本次无素材并给出告警。 + - ``knowledge_base``(知识库检索 / 内网直连检索):**直连内网知识库 ES 接口** + (``IntranetSearchProvider``),不编排任何技能、也不跑通用 provider。接口地址取 + ``ai_writing.intranet_search_url``,**留空时回退 provider 内置默认内网端点**——与旧版 + ``get_search_provider(search_provider=intranet)`` 一致,即便没配地址内网直连仍可用。 - ``notebook``(我的空间):仅用笔记 API 素材。 旧值 ``skill`` 仍按 ``general`` 兼容处理。 @@ -568,57 +569,50 @@ async def researcher_node(state: AIWritingState, config: RunnableConfig) -> dict # 仅使用 Step 1.5 已拉取的 notebook_materials。 _emit(f"仅使用笔记素材,跳过技能检索({len(notebook_materials)} 条)") elif material_source == "knowledge_base": - # ── 知识库检索:直连内网 ES 接口 ── - # 用户在表单选了「知识库检索」→ 跳过技能编排、跳过通用 provider, - # 直接调 config.yaml 配的 ai_writing.intranet_search_url 内网知识库 ES 接口 - # (IntranetSearchProvider)对检索词并发检索。未配置地址 → 无素材 + 告警。 - intranet_url = (ai_writing_config.get("intranet_search_url") or "").strip() - if not intranet_url: - _emit("未配置内网知识库检索接口(ai_writing.intranet_search_url),本次未检索到素材") - search_errors.append("未配置 ai_writing.intranet_search_url,知识库检索不可用") - _emit_skill_step({ - "type": "skill_error", - "message": "「知识库检索」未配置内网接口地址(ai_writing.intranet_search_url),无法检索", - "skill_name": KNOWLEDGE_SEARCH_SKILL_NAME, - "reason": "intranet_search_url 为空", - }) - else: - from ..search.intranet_stub import IntranetSearchProvider + # ── 知识库检索:直连内网 ES 接口(恢复旧版「内网直连检索」可用逻辑)── + # 用户在表单选了「知识库检索」→ 跳过技能编排、跳过通用 provider,直接调内网知识库 + # ES 接口(IntranetSearchProvider)对检索词并发检索。接口地址优先取 config.yaml 的 + # ai_writing.intranet_search_url;**留空时回退到 IntranetSearchProvider 内置默认端点** + # (历史上一直可用的内网 ES 地址),与旧版 get_search_provider(search_provider=intranet) + # 完全一致——所以即便没配地址,内网直连依然可用,不再短路成「未配置 → 无素材」。 + from ..search.intranet_stub import IntranetSearchProvider - provider = IntranetSearchProvider( - base_url=intranet_url, - knowledge_base_name=ai_writing_config.get("intranet_knowledge_base", "samples"), - # 内网慢检索超时可在 config.yaml 的 ai_writing.intranet_search_timeout 调大,默认 600s。 - timeout=ai_writing_config.get("intranet_search_timeout", 600), - ) - # 用户输入框追加(is_user_query_search)时 keywords 已是 [用户原话],全部检索; - # 首次检索按 keyword_count 截断检索词。 - search_keywords = keywords if is_user_query_search else keywords[:keyword_count] - total = len(search_keywords) - per_keyword = _per_keyword_limit(max_materials, total) - _emit(f"知识库检索:直连内网接口检索 {total} 个方向…") - _emit_skill_step({ - "type": "invoke_skill", - "message": f"使用「{_KNOWLEDGE_SKILL_DISPLAY}」直连内网接口检索 {total} 个方向:{('、'.join(search_keywords[:3]))[:60]}", - "skill_name": KNOWLEDGE_SEARCH_SKILL_NAME, - }) - gathered = await asyncio.gather( - *[provider.search(kw, max_results=per_keyword) for kw in search_keywords], - return_exceptions=True, - ) - for results in gathered: - if isinstance(results, Exception): - logger.warning("[knowledge-base] search failed: %s", results) - search_errors.append(f"{type(results).__name__}: {results}") - continue - new_results.extend(results or []) - search_errors.extend(getattr(provider, "errors", [])) - _emit_skill_step({ - "type": "skill_result", - "message": f"「{_KNOWLEDGE_SKILL_DISPLAY}」(内网接口)检索到 {len(new_results)} 条素材", - "skill_name": KNOWLEDGE_SEARCH_SKILL_NAME, - "matched_count": len(new_results), - }) + intranet_url = (ai_writing_config.get("intranet_search_url") or "").strip() + provider = IntranetSearchProvider( + base_url=intranet_url, # 空串 → provider 内部回退默认内网端点(旧逻辑) + knowledge_base_name=ai_writing_config.get("intranet_knowledge_base", "samples"), + # 内网慢检索超时可在 config.yaml 的 ai_writing.intranet_search_timeout 调大,默认 600s。 + timeout=ai_writing_config.get("intranet_search_timeout", 600), + ) + endpoint_label = intranet_url or getattr(provider, "endpoint", "内置默认内网端点") + # 用户输入框追加(is_user_query_search)时 keywords 已是 [用户原话],全部检索; + # 首次检索按 keyword_count 截断检索词。 + search_keywords = keywords if is_user_query_search else keywords[:keyword_count] + total = len(search_keywords) + per_keyword = _per_keyword_limit(max_materials, total) + _emit(f"知识库检索:直连内网接口检索 {total} 个方向…") + _emit_skill_step({ + "type": "invoke_skill", + "message": f"使用「{_KNOWLEDGE_SKILL_DISPLAY}」直连内网接口({endpoint_label})检索 {total} 个方向:{('、'.join(search_keywords[:3]))[:60]}", + "skill_name": KNOWLEDGE_SEARCH_SKILL_NAME, + }) + gathered = await asyncio.gather( + *[provider.search(kw, max_results=per_keyword) for kw in search_keywords], + return_exceptions=True, + ) + for results in gathered: + if isinstance(results, Exception): + logger.warning("[knowledge-base] search failed: %s", results) + search_errors.append(f"{type(results).__name__}: {results}") + continue + new_results.extend(results or []) + search_errors.extend(getattr(provider, "errors", [])) + _emit_skill_step({ + "type": "skill_result", + "message": f"「{_KNOWLEDGE_SKILL_DISPLAY}」(内网接口)检索到 {len(new_results)} 条素材", + "skill_name": KNOWLEDGE_SEARCH_SKILL_NAME, + "matched_count": len(new_results), + }) elif is_append_only: # ── 兼容旧版追加关键词模式 ── # 直接对用户给的关键词做原生并发检索(不走技能编排),结果追加到旧素材。 diff --git a/offline-backend-20260512/backend/tests/test_ai_writing_knowledge_base.py b/offline-backend-20260512/backend/tests/test_ai_writing_knowledge_base.py index 99fa41b0..02a064f5 100644 --- a/offline-backend-20260512/backend/tests/test_ai_writing_knowledge_base.py +++ b/offline-backend-20260512/backend/tests/test_ai_writing_knowledge_base.py @@ -88,12 +88,16 @@ async def test_knowledge_base_hits_intranet_directly(monkeypatch): @pytest.mark.asyncio -async def test_knowledge_base_no_url_empty(monkeypatch): - """未配置内网接口地址:无素材,且不实例化 provider。""" +async def test_knowledge_base_no_url_falls_back_to_default_endpoint(monkeypatch): + """未配置接口地址:仍实例化 IntranetSearchProvider(base_url 传空串,由 provider 内部 + 回退默认内网端点),内网直连依然可用——恢复旧版 search_provider=intranet 的行为。""" _patch(monkeypatch, intranet_url="") out = await R.researcher_node(_state(), {"configurable": {}}) - assert out["material_package"]["materials"] == [] - assert _FakeIntranet.instances == [], "无地址时不应实例化内网 provider" + mats = out["material_package"]["materials"] + assert mats, "无地址时应回退默认内网端点,仍返回素材" + assert all(m["source_type"] == "intranet" for m in mats) + assert _FakeIntranet.instances, "应实例化 IntranetSearchProvider 直连内网接口" + assert _FakeIntranet.instances[0].kw.get("base_url") == "", "空地址应原样下传,由 provider 回退默认端点" @pytest.mark.asyncio From 2097587b421670556df562d56beabeca1693ff07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=87=AF?= Date: Fri, 26 Jun 2026 22:54:10 +0800 Subject: [PATCH 2/6] =?UTF-8?q?feat(ai=E5=86=99=E4=BD=9C):=20=E5=B7=A6?= =?UTF-8?q?=E4=BE=A7=E7=A0=94=E7=A9=B6=E6=A0=8F=E5=8A=A0=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=88=97=E8=A1=A8(=E5=8F=82=E8=80=83?= =?UTF-8?q?=E4=BC=9A=E5=95=86=E6=A0=B7=E5=BC=8F)+=E4=BE=A7=E6=A0=8F?= =?UTF-8?q?=E5=8F=AF=E6=94=B6=E8=B5=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ResearchSidebar 底部新增「历史记录」列表,跟随侧栏自然滚动;样式对齐 多智能体会商 HistoryDropdown(圆角卡片+divide-y+状态药丸+打开/改名/删除) - 点历史记录在右侧区域显示历史回看,左侧栏保留(showSidebar 含历史态) - 侧栏顶部加「收起」按钮,收起为细窄展开条(页面承载 sidebarCollapsed) - 「挂起中」记录点击经 window 事件 ai-writing:show-progress 打开进度流程图弹窗 Co-Authored-By: Claude Opus 4.8 (1M context) --- .../components/ai-writing/AIWritingPanel.tsx | 10 + .../components/ai-writing/ResearchSidebar.tsx | 227 +++++++++++++++++- .../src/open-canvas/pages/AIWritingPage.tsx | 42 +++- 3 files changed, 266 insertions(+), 13 deletions(-) diff --git a/frontend-web/src/open-canvas/components/ai-writing/AIWritingPanel.tsx b/frontend-web/src/open-canvas/components/ai-writing/AIWritingPanel.tsx index 8dc166b8..a80bb281 100644 --- a/frontend-web/src/open-canvas/components/ai-writing/AIWritingPanel.tsx +++ b/frontend-web/src/open-canvas/components/ai-writing/AIWritingPanel.tsx @@ -284,6 +284,16 @@ export function AIWritingPanel({ return () => window.removeEventListener('ai-writing:open-session', onOpenSession); }, []); + // 路径4:左侧研究栏「历史记录」点「挂起中」记录 → 打开进度流程图弹窗(与下拉历史一致)。 + useEffect(() => { + function onShowProgress(e: Event) { + const session = (e as CustomEvent).detail; + if (session) setProgressSession(session); + } + window.addEventListener('ai-writing:show-progress', onShowProgress); + return () => window.removeEventListener('ai-writing:show-progress', onShowProgress); + }, []); + // 路径3:URL ?session=xxx 直接定位到指定会话 useEffect(() => { const sessionId = searchParams.get('session'); diff --git a/frontend-web/src/open-canvas/components/ai-writing/ResearchSidebar.tsx b/frontend-web/src/open-canvas/components/ai-writing/ResearchSidebar.tsx index f161a0dd..dbccda73 100644 --- a/frontend-web/src/open-canvas/components/ai-writing/ResearchSidebar.tsx +++ b/frontend-web/src/open-canvas/components/ai-writing/ResearchSidebar.tsx @@ -3,20 +3,26 @@ import { BarChart3, BookOpen, + Eye, FileText, Globe2, + History, LayoutGrid, Loader2, Newspaper, + PanelLeftClose, + Pencil, Plus, + RefreshCw, Search, Settings2, SlidersHorizontal, Sparkles, + Trash2, TrendingUp, } from "lucide-react"; import type { LucideIcon } from "lucide-react"; -import { useEffect, useMemo, useState } from "react"; +import { useEffect, useMemo, useRef, useState } from "react"; import { useNavigate } from "react-router-dom"; import { useQueryClient } from "@tanstack/react-query"; @@ -33,9 +39,13 @@ import { useStudioNotebooks } from "@/core/studio/hooks"; import { cn } from "@/lib/utils"; import { useResearchTemplates } from "../../hooks/useResearchTemplates"; +import { useAIWritingSessions } from "../../hooks/useAIWritingSessions"; import type { ResearchTemplate } from "../../api/ai-writing-research-templates"; +import type { AIWritingSessionSummary } from "../../api/ai-writing-sessions"; import { useWritingForm } from "../../contexts/WritingFormContext"; import { useAIWriting } from "../../contexts/AIWritingContext"; +import { useAIWritingHistory } from "../../contexts/AIWritingHistoryContext"; +import { formatRelative } from "./AIWritingHistoryDropdown"; type TemplateVisual = { Icon: LucideIcon; @@ -86,14 +96,142 @@ function getTemplateVisual(tpl: ResearchTemplate, index: number): TemplateVisual return TEMPLATE_VISUALS[index % TEMPLATE_VISUALS.length]; } +// 历史记录状态药丸样式(对齐多智能体会商的历史记录观感)。 +const WRITING_STATUS_PILL: Record = { + in_progress: { label: "进行中", className: "text-primary", spin: true }, + background: { label: "挂起中", className: "text-sky-500", spin: true }, + draft_ready: { label: "草稿", className: "text-amber-500" }, + review_ready: { label: "审核", className: "text-purple-500", dot: true }, + done: { label: "完成", className: "text-emerald-500" }, + error: { label: "出错", className: "text-rose-500" }, +}; + +/** 单条历史记录项 —— 样式参考多智能体会商的 HistoryDropdown 列表项(圆角卡片 + 状态药丸 + 操作按钮)。 */ +function WritingHistoryItem({ + session, + isCurrent, + onSelect, + onShowProgress, + onDelete, + onRename, +}: { + session: AIWritingSessionSummary; + isCurrent: boolean; + onSelect: () => void; + onShowProgress?: () => void; + onDelete: () => void; + onRename: (title: string) => void; +}) { + const [renaming, setRenaming] = useState(false); + const [value, setValue] = useState(session.title); + const inputRef = useRef(null); + const isBackground = session.status === "background"; + // 「挂起中」点击看进度(流程图弹窗),其余打开历史回看。 + const open = isBackground && onShowProgress ? onShowProgress : onSelect; + const pill = WRITING_STATUS_PILL[session.status] ?? { label: session.status, className: "text-slate-400" }; + + useEffect(() => { + if (renaming) inputRef.current?.focus(); + }, [renaming]); + + const commit = () => { + const t = value.trim(); + if (t && t !== session.title) onRename(t); + setRenaming(false); + }; + + return ( +
  • +
    +
    + {renaming ? ( + setValue(e.target.value)} + onKeyDown={(e) => { + if (e.key === "Enter") commit(); + if (e.key === "Escape") { + setValue(session.title); + setRenaming(false); + } + }} + onBlur={commit} + className="w-full rounded border border-slate-300 px-2 py-1 text-[11.5px] font-semibold text-slate-800 outline-none focus:border-primary" + /> + ) : ( + + )} +
    + + {!renaming && ( +
    + + + +
    + )} +
    +
  • + ); +} + export function ResearchSidebar({ viewingNotebookId, onOpenNotebook, onOpenAllSpaces, + onCollapse, }: { viewingNotebookId?: number | null; onOpenNotebook: (notebookId: number) => void; onOpenAllSpaces: () => void; + /** 收起侧栏(由页面承载收起态)。 */ + onCollapse?: () => void; }) { const navigate = useNavigate(); const { templates, refresh } = useResearchTemplates(); @@ -116,6 +254,31 @@ export function ResearchSidebar({ } = useWritingForm(); const queryClient = useQueryClient(); + // 「历史记录」列表(左下角,样式参考多智能体会商的历史记录):自带一份会话列表, + // 点击打开「历史回看」(openHistory,全局共享上下文,打开后本侧栏随写作进入历史态而隐藏)。 + const { + sessions, + loading: sessionsLoading, + refresh: refreshSessions, + rename: renameSession, + remove: removeSession, + } = useAIWritingSessions(); + const { openHistory, historySession } = useAIWritingHistory(); + + // 进入/返回写作配置页时刷新一次历史(本侧栏仅在 idle 态挂载,故等同每次回到表单刷新)。 + useEffect(() => { + void refreshSessions(); + }, [refreshSessions]); + + const handleSelectHistory = (session: AIWritingSessionSummary) => { + void openHistory(session); + }; + // 「挂起中」记录:交给右侧面板打开进度流程图弹窗(沿用面板已有的 window 事件解耦模式, + // 与 ai-writing:open-session 一致),本侧栏不直接持有弹窗状态。 + const handleShowProgress = (session: AIWritingSessionSummary) => { + window.dispatchEvent(new CustomEvent("ai-writing:show-progress", { detail: session })); + }; + const [templateSearch, setTemplateSearch] = useState(""); const [createOpen, setCreateOpen] = useState(false); const [name, setName] = useState(""); @@ -191,6 +354,20 @@ export function ResearchSidebar({ return (