feat(roundtable): 深链策划流程小图 + 流程图弹窗横向/缩略图/深蓝适配
- Step1 消息列表头部:深链 taskId 模式取到目的树后,左侧标题换成「策划流程」 彩色层级小图(任务→目的→…→叙事,每级配色对齐流程图节点 + 类型小图标), 点击打开任务目的流程图弹窗;仅第一步、有数据时出现。 - TaskPurposeDialog 流程图:横向(LR)布局 + 右下角缩略图(MiniMap)。 - FlowGraphPanel 深蓝主题适配(随 ThemeContext):容器/头部/画布点阵/连线/图例/ 小地图/节点详情弹窗 + 节点配色(FLOW_NODE_TYPE_META_DARK),浅色红主题不受影响。 - 圆桌侧栏深色兜底:neutral 家族 + 米色 hex(#FAF6F5/#ECE7E4/#E8D0CC) 映射到深蓝 token(关系图背板、第N步 tag 等不再泛白)。 附带提交工作区其余暂存改动(AI 写作等),不含 config.yaml。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
85cca36ddb
commit
03b6fb724c
40 files changed
+2167
-119
No files matched your search
+23
-3
@@ -169,7 +169,19 @@ async def pause_outline_confirm(state: AIWritingState) -> dict:
|
||||
|
||||
async def pause_draft_confirm(state: AIWritingState, config: RunnableConfig) -> dict:
|
||||
"""PAUSE-3:草稿确认"""
|
||||
draft = state["current_draft"]
|
||||
draft = state.get("current_draft")
|
||||
# 防御:草稿缺失(写作节点异常未产出)时不进入确认暂停,转 error 优雅结束,
|
||||
# 避免 draft["title"] 在 None 上崩溃。正常路径下 after_writer_draft 已拦截
|
||||
# status:error,这里是兜底第二道防线(如 editor 异常等边角情形)。
|
||||
if not draft:
|
||||
return {
|
||||
"status": "error",
|
||||
"progress_events": [{
|
||||
"type": "error", "agent_name": "作家",
|
||||
"title": "草稿缺失", "detail": "草稿尚未生成,无法进入确认环节,请重试。",
|
||||
"message": "草稿生成失败",
|
||||
}],
|
||||
}
|
||||
user_input: dict = interrupt({
|
||||
"pause_point": "draft_confirm",
|
||||
"message": "草稿已完成,请确认或给出修改意见。",
|
||||
@@ -308,7 +320,15 @@ def after_outline_pause(state: AIWritingState) -> str:
|
||||
|
||||
|
||||
def after_writer_draft(state: AIWritingState) -> str:
|
||||
"""写作完成后:素材不足则去求助暂停点,否则去草稿确认。"""
|
||||
"""写作完成后:素材不足则去求助暂停点,否则去草稿确认。
|
||||
|
||||
写作节点兜底成 ``status:error``(如模型创建失败)时直接结束本次 run —— 否则会
|
||||
流到 pause_draft,而此时 ``current_draft`` 为 None,``pause_draft_confirm`` 取
|
||||
``draft["title"]`` 会二次崩溃('NoneType' object is not subscriptable)。错误事件
|
||||
已由写作节点 emit,run 优雅结束即可,用户重试不受影响。
|
||||
"""
|
||||
if state["status"] == "error":
|
||||
return "end"
|
||||
return "pause_section_help" if state["status"] == "awaiting_section_help" else "pause_draft"
|
||||
|
||||
|
||||
@@ -377,7 +397,7 @@ def make_ai_writing_graph(config=None):
|
||||
g.add_conditional_edges("pause_outline", after_outline_pause,
|
||||
{"writer_outline": "writer_outline", "writer_draft": "writer_draft"})
|
||||
g.add_conditional_edges("writer_draft", after_writer_draft,
|
||||
{"pause_section_help": "pause_section_help", "pause_draft": "pause_draft"})
|
||||
{"pause_section_help": "pause_section_help", "pause_draft": "pause_draft", "end": END})
|
||||
g.add_conditional_edges("pause_section_help", after_section_help_pause,
|
||||
{"researcher": "researcher", "writer_draft": "writer_draft"})
|
||||
g.add_conditional_edges("pause_draft", after_draft_pause,
|
||||
|
||||
+6
-4
@@ -126,9 +126,11 @@ def resolve_agent_model_name(
|
||||
传入,如 researcher 的 keyword_model/rank_model)> ``state.model_name``
|
||||
(用户写作表单选的主模型)> configurable.model_name。
|
||||
|
||||
strict=True(大纲/写作/审核):全部为空抛 ValueError(与 get_writing_model
|
||||
口径一致——不静默回退默认模型);strict=False(researcher 辅助任务):
|
||||
返回 None,由 create_chat_model 回退 config.yaml 的 models[0]。
|
||||
全部为空时**不再抛错**(旧实现 strict=True 抛 ValueError 会把「未选模型」直接打成
|
||||
草稿失败,且后续 pause_draft 还会因 current_draft 为空二次崩溃):统一返回 None,
|
||||
由 create_chat_model 回退 config.yaml 的 ``models[0]``。``strict`` 仅用于区分日志
|
||||
级别——大纲/写作/审核阶段缺模型属异常配置,记 warning,调用方据 None 向用户提示
|
||||
「已用默认模型」。
|
||||
"""
|
||||
candidates = (
|
||||
(getattr(agent_cfg, "model", None) or "") if agent_cfg else "",
|
||||
@@ -140,7 +142,7 @@ def resolve_agent_model_name(
|
||||
if isinstance(name, str) and name.strip():
|
||||
return name.strip()
|
||||
if strict:
|
||||
raise ValueError("未指定写作模型(model_name 为空):请在写作表单选择模型后重试")
|
||||
logger.warning("写作模型未指定(state/configurable/agent.model 均为空),回退默认模型")
|
||||
return None
|
||||
|
||||
|
||||
|
||||
+177
@@ -0,0 +1,177 @@
|
||||
"""像「智能体调用技能」那样用一个技能检索素材。
|
||||
|
||||
背景:素材收集专家(ai-writing-researcher)是内置智能体,但此前它「用技能检索」只是
|
||||
拿技能的 ``description`` 拼一个 query 丢给通用 web/intranet 检索 provider——技能自己
|
||||
SKILL.md 里写的检索说明 / 策略并没有真正跑起来,和真实智能体「读 SKILL.md → 按说明
|
||||
调工具检索」的逻辑不一致。
|
||||
|
||||
本模块把两者对齐:把技能 **SKILL.md 全文**连同素材收集专家 SOUL 注入 system prompt,
|
||||
给模型绑定一个 ``search`` 工具,跑一个**有界的工具调用循环**——模型按技能说明自行决定
|
||||
检索词与轮次(就像智能体读了技能后驱动检索),我们直接**收割工具返回的 SearchResult**
|
||||
作为素材(无需再从自由文本里抽取,检索 provider 的结果本就是结构化素材)。
|
||||
|
||||
仅在 ``config.yaml → ai_writing.researcher_skill_agent`` 打开时启用(默认 false,走旧的
|
||||
description→检索 直连路径)。弱模型不会工具调用 / 检索失败时,调用方回退旧路径,保证
|
||||
素材不为空。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from langchain_core.runnables import RunnableConfig
|
||||
|
||||
from ._agent_runner import (
|
||||
RESEARCHER_AGENT_ID,
|
||||
WritingAgentUnavailable,
|
||||
load_writing_agent,
|
||||
resolve_agent_model_name,
|
||||
)
|
||||
from ._utils import get_ai_writing_config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# 工具调用循环上限(每轮 = 一次模型调用,可含多个 search 调用)。
|
||||
_MAX_TURNS = 4
|
||||
|
||||
|
||||
def use_skill_search_agent() -> bool:
|
||||
"""读 ``config.yaml → ai_writing.researcher_skill_agent`` 开关(默认 false,mtime 热加载)。"""
|
||||
cfg = get_ai_writing_config()
|
||||
return bool(cfg.get("researcher_skill_agent", False)) if isinstance(cfg, dict) else False
|
||||
|
||||
|
||||
def _read_skill_body(skill) -> str:
|
||||
"""读技能 SKILL.md 全文;失败回退 name+description。"""
|
||||
try:
|
||||
return skill.skill_file.read_text(encoding="utf-8")
|
||||
except Exception: # noqa: BLE001
|
||||
return f"# 技能:{getattr(skill, 'name', '')}\n{getattr(skill, 'description', '') or ''}"
|
||||
|
||||
|
||||
async def run_skill_search_agent(
|
||||
*,
|
||||
skill,
|
||||
intent: str,
|
||||
keywords: list[str],
|
||||
user_query: str,
|
||||
config: RunnableConfig,
|
||||
state: dict,
|
||||
model_name_fallback: str | None,
|
||||
max_results: int,
|
||||
timeout_s: int,
|
||||
emit_query=None,
|
||||
) -> tuple[list, str]:
|
||||
"""像智能体一样按技能 SKILL.md 检索素材。
|
||||
|
||||
Returns ``(results, error_detail)``:results 为收割到的 SearchResult 列表(调用方再
|
||||
去全局去重/合并);error_detail 非空且 results 为空 = 该技能整体失败(触发兜底)。
|
||||
模型不支持工具调用 / 始终不发起检索时返回 ``([], "")``,调用方据此回退旧检索路径。
|
||||
"""
|
||||
from langchain_core.messages import HumanMessage, SystemMessage, ToolMessage
|
||||
from langchain_core.tools import tool
|
||||
|
||||
from ..search import get_search_provider
|
||||
|
||||
skill_name = getattr(skill, "name", "") or "技能"
|
||||
skill_body = _read_skill_body(skill)
|
||||
|
||||
try:
|
||||
agent_cfg, soul = load_writing_agent(RESEARCHER_AGENT_ID)
|
||||
except WritingAgentUnavailable:
|
||||
agent_cfg, soul = None, ""
|
||||
|
||||
model_name = resolve_agent_model_name(
|
||||
agent_cfg, state, config, explicit_fallback=model_name_fallback, strict=False
|
||||
)
|
||||
|
||||
from deerflow.models import create_chat_model
|
||||
|
||||
try:
|
||||
model = create_chat_model(name=model_name)
|
||||
except Exception as e: # noqa: BLE001
|
||||
return [], f"模型创建失败: {e}"
|
||||
|
||||
@tool
|
||||
def search(query: str) -> str: # noqa: ARG001 — 仅用于给模型生成 schema,真正检索在循环里执行
|
||||
"""根据 query 检索素材。一次只传一个检索词;可多次调用以覆盖不同角度。"""
|
||||
return ""
|
||||
|
||||
try:
|
||||
model_tools = model.bind_tools([search])
|
||||
except Exception as e: # noqa: BLE001 — 模型不支持工具调用
|
||||
logger.info("skill agent: model lacks tool-calling, fallback. err=%s", e)
|
||||
return [], ""
|
||||
|
||||
provider = get_search_provider(get_ai_writing_config())
|
||||
|
||||
system = (
|
||||
(soul + "\n\n" if soul else "")
|
||||
+ "你现在挂载了下面这个检索技能,请**严格按它的说明**来检索素材。\n"
|
||||
"通过调用 search 工具执行检索(一次一个检索词,可多次调用覆盖不同角度/来源);\n"
|
||||
"收集到足够素材后直接回复「检索完成」即可,不要编造任何内容。\n\n"
|
||||
f"=== 技能:{skill_name} ===\n{skill_body}"
|
||||
)
|
||||
task_lines = [f"写作意图:{intent or '(无)'}"]
|
||||
if user_query:
|
||||
task_lines.append(f"用户补充:{user_query}")
|
||||
if keywords:
|
||||
task_lines.append(f"可参考的检索方向:{', '.join(keywords[:8])}")
|
||||
task_lines.append(f"请按上面技能的说明检索相关素材(目标约 {max_results} 条)。")
|
||||
messages: list = [SystemMessage(content=system), HumanMessage(content="\n".join(task_lines))]
|
||||
|
||||
results: list = []
|
||||
seen_urls: set[str] = set()
|
||||
last_error = ""
|
||||
|
||||
for _turn in range(_MAX_TURNS):
|
||||
try:
|
||||
ai = await model_tools.ainvoke(messages)
|
||||
except Exception as e: # noqa: BLE001
|
||||
last_error = f"模型调用失败: {e}"
|
||||
logger.warning("skill agent[%s] model invoke failed: %s", skill_name, e)
|
||||
break
|
||||
messages.append(ai)
|
||||
tool_calls = getattr(ai, "tool_calls", None) or []
|
||||
if not tool_calls:
|
||||
break # 模型不再检索(回复「检索完成」或纯文本)
|
||||
for tc in tool_calls:
|
||||
tc_id = tc.get("id") or ""
|
||||
query = ((tc.get("args") or {}).get("query") or "").strip()
|
||||
if not query:
|
||||
messages.append(ToolMessage(content="query 为空,已跳过", tool_call_id=tc_id))
|
||||
continue
|
||||
if emit_query:
|
||||
emit_query(query)
|
||||
try:
|
||||
found = await asyncio.wait_for(
|
||||
provider.search(query, max_results=max_results), timeout=timeout_s
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
last_error = f"检索超时(>{timeout_s}s)"
|
||||
messages.append(ToolMessage(content=last_error, tool_call_id=tc_id))
|
||||
continue
|
||||
except Exception as e: # noqa: BLE001
|
||||
last_error = str(e)
|
||||
messages.append(ToolMessage(content=f"检索失败: {e}", tool_call_id=tc_id))
|
||||
continue
|
||||
added = 0
|
||||
for r in found or []:
|
||||
url = getattr(r, "url", None)
|
||||
if url and url in seen_urls:
|
||||
continue
|
||||
if url:
|
||||
seen_urls.add(url)
|
||||
results.append(r)
|
||||
added += 1
|
||||
# 给模型一个简短回执,让它据此决定是否继续换角度检索。
|
||||
sample = ";".join((getattr(r, "title", "") or "")[:40] for r in (found or [])[:5]) or "无结果"
|
||||
messages.append(
|
||||
ToolMessage(content=f"检索到 {added} 条新素材。标题样例:{sample}", tool_call_id=tc_id)
|
||||
)
|
||||
if len(results) >= max_results:
|
||||
break
|
||||
|
||||
if not results and last_error:
|
||||
return [], last_error
|
||||
return results, ""
|
||||
+18
-12
@@ -74,24 +74,30 @@ def get_model(config: RunnableConfig, model_name: str | None = None):
|
||||
return create_chat_model(name=name)
|
||||
|
||||
|
||||
def get_writing_model(config: RunnableConfig, state: dict):
|
||||
"""大纲 / 写作 / 审核专用:严格使用用户在表单选定的模型,**不回退默认**。
|
||||
def resolve_writing_model_name(config: RunnableConfig, state: dict) -> tuple[str | None, bool]:
|
||||
"""解析大纲 / 写作 / 审核阶段使用的模型名,返回 ``(name, used_default)``。
|
||||
|
||||
用户模型在 intent_parser(首次 invocation,configurable.model_name 可用)阶段
|
||||
捕获进 ``state['model_name']``,经 checkpoint 持久化。这三个节点都在
|
||||
「确认素材 / 大纲」resume 之后才运行,而 resume 是新 invocation、其 config 不再
|
||||
带 model_name —— 所以必须从 state 读,不能从 configurable 读(否则回退到 config
|
||||
列表第一个模型,常是推理模型,既影响质量也会让 reasoning_content 走不出流式)。
|
||||
优先级:``state['model_name']``(用户在表单选定,由 intent_parser 在首次
|
||||
invocation 捕获并经 checkpoint 持久化)> ``configurable.model_name``(同一
|
||||
invocation 内直跑、或前端在 resume 时一并回传的兜底)。
|
||||
|
||||
缺失视为配置错误直接抛 ValueError —— 由各节点的 try/except 兜底成 status:error,
|
||||
而不是静默回退默认模型。
|
||||
interrupt/resume 是新 invocation,其 config 默认不带原 model_name,所以正常情况
|
||||
要从 state 读。两者皆空(历史会话 / 首轮捕获就为空 / 前端没传)时不再视为致命
|
||||
错误,而是返回 ``(None, True)``:调用方据此回退 config.yaml 的 ``models[0]`` 并向
|
||||
用户提示「未选模型,已用默认模型」,保证写作流程不被一个空模型名硬卡住。
|
||||
"""
|
||||
name = ((state or {}).get("model_name") or "").strip()
|
||||
if not name:
|
||||
# 兜底再看一眼 configurable(首次同 invocation 内直跑到这里的极端情况)
|
||||
name = (config.get("configurable", {}).get("model_name", "") or "").strip()
|
||||
if not name:
|
||||
raise ValueError("未指定写作模型(model_name 为空):请在写作表单选择模型后重试")
|
||||
if name:
|
||||
return name, False
|
||||
logger.warning("写作模型未指定(state/configurable 均为空),回退默认模型")
|
||||
return None, True
|
||||
|
||||
|
||||
def get_writing_model(config: RunnableConfig, state: dict):
|
||||
"""大纲 / 写作 / 审核:解析用户选定模型,缺失时回退默认模型(见 resolve_writing_model_name)。"""
|
||||
name, _ = resolve_writing_model_name(config, state)
|
||||
from deerflow.models import create_chat_model
|
||||
return create_chat_model(name=name)
|
||||
|
||||
|
||||
+44
-6
@@ -40,6 +40,7 @@ from ._agent_runner import (
|
||||
run_writing_agent,
|
||||
use_builtin_agent,
|
||||
)
|
||||
from ._skill_agent import run_skill_search_agent, use_skill_search_agent
|
||||
from ._utils import get_ai_writing_config, llm_json, safe_get_stream_writer
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -83,10 +84,21 @@ _MAX_MAX_MATERIALS = 100
|
||||
_DEFAULT_KEYWORD_COUNT = 6
|
||||
_MAX_KEYWORD_COUNT = 10
|
||||
|
||||
# 单个技能的 web 检索超时(秒)。技能检索是顺序循环,
|
||||
# DuckDuckGo 等 provider 偶发限速/挂起会把整段"技能检索过程"拖到几十秒看起来卡死;
|
||||
# 超时即放弃该技能、emit 0 条结果继续下一个,保证时间线持续推进。
|
||||
_SKILL_SEARCH_TIMEOUT_SECONDS = 25
|
||||
# 单个技能的检索超时(秒)。技能检索是顺序循环,provider 偶发限速/挂起会把整段
|
||||
# "技能检索过程"拖住;超时即放弃该技能、emit 0 条结果继续下一个,保证时间线持续推进。
|
||||
# 默认 120s(≥2 分钟):内网检索 provider 本身就允许 timeout=120,之前 25s 会过早放弃
|
||||
# 慢但有效的检索。可用环境变量 AI_WRITING_SKILL_SEARCH_TIMEOUT_SECONDS 覆盖。
|
||||
def _env_int(name: str, default: int) -> int:
|
||||
raw = (os.getenv(name) or "").strip()
|
||||
if raw:
|
||||
try:
|
||||
return max(1, int(raw))
|
||||
except ValueError:
|
||||
pass
|
||||
return default
|
||||
|
||||
|
||||
_SKILL_SEARCH_TIMEOUT_SECONDS = _env_int("AI_WRITING_SKILL_SEARCH_TIMEOUT_SECONDS", 120)
|
||||
|
||||
# 内置「知识库检索」技能名:素材收集专家 agent 的默认技能。researcher 对它
|
||||
# 特殊处理——不用 description 拼 query,而是对 Step 1 生成的全部检索词做
|
||||
@@ -607,8 +619,34 @@ async def researcher_node(state: AIWritingState, config: RunnableConfig) -> dict
|
||||
error_detail = ";".join(dict.fromkeys(errs))[:200]
|
||||
return added, error_detail
|
||||
else:
|
||||
# 定向技能检索:user_query 模式优先用用户原话;非知识库技能再
|
||||
# 附上 description 让 query 贴合该技能的领域。
|
||||
# ── 智能体式技能调用(config ai_writing.researcher_skill_agent 打开时)──
|
||||
# 把技能 SKILL.md 注入 + 绑定 search 工具,让模型按技能说明驱动检索,
|
||||
# 收割工具返回的 SearchResult 作为素材(与「智能体调用技能」逻辑一致)。
|
||||
if use_skill_search_agent():
|
||||
def _emit_q(q: str, _name=sk.name) -> None:
|
||||
_emit_skill_step({
|
||||
"type": "invoke_skill",
|
||||
"message": f"素材收集专家用技能「{_name}」检索:{q[:60]}",
|
||||
"skill_name": _name,
|
||||
})
|
||||
agent_results, agent_err = await run_skill_search_agent(
|
||||
skill=sk,
|
||||
intent=intent,
|
||||
keywords=keywords,
|
||||
user_query=user_query if is_user_query_search else "",
|
||||
config=config,
|
||||
state=state,
|
||||
model_name_fallback=keyword_model,
|
||||
max_results=per_skill,
|
||||
timeout_s=_SKILL_SEARCH_TIMEOUT_SECONDS,
|
||||
emit_query=_emit_q,
|
||||
)
|
||||
if agent_results:
|
||||
return _collect(agent_results), ""
|
||||
# 弱模型不会工具调用 / 智能体检索失败 → 回退直连检索,保证素材不空。
|
||||
|
||||
# 定向技能检索(默认路径 / 智能体模式回退):user_query 模式优先用用户原话;
|
||||
# 非知识库技能再附上 description 让 query 贴合该技能的领域。
|
||||
if is_user_query_search:
|
||||
skill_query = user_query if is_knowledge else f"{user_query} {sk.description or ''}".strip()
|
||||
else:
|
||||
|
||||
+20
-4
@@ -21,7 +21,7 @@ from ._agent_runner import (
|
||||
stream_writing_agent,
|
||||
use_builtin_agent,
|
||||
)
|
||||
from ._utils import get_writing_model, _content_to_text, count_words, reasoning_delta, ThinkTagParser, safe_get_stream_writer
|
||||
from ._utils import resolve_writing_model_name, _content_to_text, count_words, reasoning_delta, ThinkTagParser, safe_get_stream_writer
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -209,11 +209,18 @@ async def writer_draft_node(state: AIWritingState, config: RunnableConfig) -> di
|
||||
use_agent = use_builtin_agent("writer")
|
||||
agent_label = "作家"
|
||||
model = None
|
||||
# 未选模型回退默认时给用户一条非致命提示(最终随草稿一并返回)
|
||||
model_default_notice: dict | None = None
|
||||
if use_agent:
|
||||
try:
|
||||
agent_cfg, _soul = load_writing_agent(WRITER_AGENT_ID)
|
||||
# 模型守卫提前到循环外:模型名缺失/配错与旧路径同样转成 status:error
|
||||
resolve_agent_model_name(agent_cfg, state, config)
|
||||
# 模型解析提前到循环外:返回 None 表示 state/configurable/agent.model 全空,
|
||||
# 后续 create_chat_model 会回退默认模型,这里据此准备一条用户提示。
|
||||
if resolve_agent_model_name(agent_cfg, state, config) is None:
|
||||
model_default_notice = {
|
||||
"type": "notice", "agent_name": agent_display_name(WRITER_AGENT_ID, "作家"),
|
||||
"title": "模型提示", "detail": "未检测到所选写作模型,已使用默认模型继续写作。",
|
||||
}
|
||||
agent_label = agent_display_name(WRITER_AGENT_ID, "作家")
|
||||
except WritingAgentUnavailable as e:
|
||||
logger.warning("writer builtin agent unavailable, falling back to legacy prompts: %s", e)
|
||||
@@ -231,7 +238,14 @@ async def writer_draft_node(state: AIWritingState, config: RunnableConfig) -> di
|
||||
# 模型创建守卫:模型名配错时 create_chat_model 抛 ValueError,
|
||||
# 不拦截会硬崩溃整个图;此处转成可恢复的 status:error。
|
||||
try:
|
||||
model = get_writing_model(config, state)
|
||||
model_name, used_default = resolve_writing_model_name(config, state)
|
||||
if used_default:
|
||||
model_default_notice = {
|
||||
"type": "notice", "agent_name": "作家",
|
||||
"title": "模型提示", "detail": "未检测到所选写作模型,已使用默认模型继续写作。",
|
||||
}
|
||||
from deerflow.models import create_chat_model
|
||||
model = create_chat_model(name=model_name)
|
||||
except Exception as e:
|
||||
logger.error("draft model creation failed: %s", e, exc_info=True)
|
||||
return {
|
||||
@@ -449,6 +463,8 @@ async def writer_draft_node(state: AIWritingState, config: RunnableConfig) -> di
|
||||
|
||||
# 分节写作出现模型异常时,以非致命 notice 提示用户,草稿仍照常产出
|
||||
notices: list[dict] = []
|
||||
if model_default_notice:
|
||||
notices.append(model_default_notice)
|
||||
if section_errors:
|
||||
notices.append({
|
||||
"type": "notice",
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ logger = logging.getLogger(__name__)
|
||||
class DuckDuckGoSearchProvider(BaseSearchProvider):
|
||||
"""使用 DuckDuckGo 进行互联网搜索,无需 API Key。"""
|
||||
|
||||
def __init__(self, region: str = "cn-zh", max_timeout: int = 30):
|
||||
def __init__(self, region: str = "cn-zh", max_timeout: int = 120):
|
||||
self.region = region
|
||||
self.max_timeout = max_timeout
|
||||
# 收集本次运行的检索异常,供 researcher 节点取出并提示用户
|
||||
|
||||
+15
@@ -207,6 +207,21 @@ class AIWritingSessionRepository:
|
||||
await session.commit()
|
||||
return True
|
||||
|
||||
async def list_by_status(self, status: str, *, limit: int = 500) -> list[dict]:
|
||||
"""列出指定 status 的会话(仅 id + user_id,用于后台驱动重启续跑 reconcile)。
|
||||
|
||||
不按 user_id 过滤——进程级 reconcile 要把所有用户「挂起中」的会话都拉起。
|
||||
"""
|
||||
stmt = (
|
||||
select(AIWritingSessionRow.id, AIWritingSessionRow.user_id)
|
||||
.where(AIWritingSessionRow.status == status)
|
||||
.order_by(AIWritingSessionRow.updated_at.asc())
|
||||
.limit(limit)
|
||||
)
|
||||
async with self._sf() as session:
|
||||
result = await session.execute(stmt)
|
||||
return [{"id": row[0], "user_id": row[1]} for row in result.all()]
|
||||
|
||||
async def list_older_than(
|
||||
self,
|
||||
cutoff: datetime,
|
||||
|
||||
Reference in new issue
Block a user