chore(persistence): 增加 Workflow Studio 表重建开关与迁移兼容修正

提交内容:为数据库生命周期增加按白名单清单重建 Workflow Studio 表的受限流程,限定仅 MySQL 且检查当前连接数据库名称一致,避免误删非目标 schema。

启动流程中新增 DEER_FLOW_REBUILD_WORKFLOW_SCHEMA 环境变量入口与持久层重建 API,并在 lifespan 里按需执行;导出到 persistence 包,便于后续调用与测试复用。

迁移与模型修复:将 workflow 相关大文本字段切到 MySQL LONGTEXT,不再给 TEXT/LONGTEXT 设置 server_default;新增 draft_canvas_schema_json 的迁移回填与非空约束变更,规避 MySQL 5.7 对默认值限制。

测试覆盖:补充 workflow 定义 ddl 长文本断言与 schema 重建保护性测试(仅允许清单表、数据库名不匹配直接拒绝),并把新测试文件加入版本追踪。
This commit is contained in:
董宏凯 committed 2026-08-31 16:45:06 +08:00
1 parent f0ddade8a7
commit ac92f29db1
10 files changed
+300 -39

No files matched your search

@@ -264,12 +264,35 @@ class DeerFlowClient:
return [{"name": tc["name"], "args": tc["args"], "id": tc.get("id")} for tc in tool_calls]
@staticmethod
def _ai_text_event(msg_id: str | None, text: str, usage: dict | None) -> "StreamEvent":
"""Build a ``messages-tuple`` AI text event, attaching usage when present."""
data: dict[str, Any] = {"type": "ai", "content": text, "id": msg_id}
if usage:
data["usage_metadata"] = usage
return StreamEvent(type="messages-tuple", data=data)
def _ai_text_event(
msg_id: str | None,
text: str,
usage: dict | None,
reasoning: str = "",
) -> "StreamEvent":
"""Build a ``messages-tuple`` AI text event, preserving reasoning deltas."""
data: dict[str, Any] = {"type": "ai", "content": text, "id": msg_id}
if usage:
data["usage_metadata"] = usage
# Thinking-enabled OpenAI-compatible providers commonly put their
# streaming tokens in ``additional_kwargs.reasoning_content`` while
# ``content`` remains empty. Keep it on the wire for consumers that
# render a custom stream (such as the multi-agent roundtable).
if reasoning:
data["additional_kwargs"] = {"reasoning_content": reasoning}
return StreamEvent(type="messages-tuple", data=data)
@staticmethod
def _reasoning_text(msg: Any) -> str:
"""Return a provider reasoning delta when it is available as text."""
additional_kwargs = getattr(msg, "additional_kwargs", None) or {}
if not isinstance(additional_kwargs, dict):
return ""
reasoning = (
additional_kwargs.get("reasoning_content")
or additional_kwargs.get("reasoning")
)
return reasoning if isinstance(reasoning, str) else ""
@staticmethod
def _ai_tool_calls_event(msg_id: str | None, tool_calls) -> "StreamEvent":
@@ -618,14 +641,15 @@ class DeerFlowClient:
msg_id = getattr(msg_chunk, "id", None)
if isinstance(msg_chunk, AIMessage):
text = self._extract_text(msg_chunk.content)
counted_usage = _account_usage(msg_id, msg_chunk.usage_metadata)
if text:
if msg_id:
streamed_ids.add(msg_id)
yield self._ai_text_event(msg_id, text, counted_usage)
if isinstance(msg_chunk, AIMessage):
text = self._extract_text(msg_chunk.content)
reasoning = self._reasoning_text(msg_chunk)
counted_usage = _account_usage(msg_id, msg_chunk.usage_metadata)
if text or reasoning:
if msg_id:
streamed_ids.add(msg_id)
yield self._ai_text_event(msg_id, text, counted_usage, reasoning)
if msg_chunk.tool_calls:
if msg_id:
@@ -661,9 +685,10 @@ class DeerFlowClient:
if msg.tool_calls:
yield self._ai_tool_calls_event(msg_id, msg.tool_calls)
text = self._extract_text(msg.content)
if text:
yield self._ai_text_event(msg_id, text, counted_usage)
text = self._extract_text(msg.content)
reasoning = self._reasoning_text(msg)
if text or reasoning:
yield self._ai_text_event(msg_id, text, counted_usage, reasoning)
elif isinstance(msg, ToolMessage):
yield self._tool_message_event(msg)