Merge remote-tracking branch 'origin/master' into ji
# Conflicts: # frontend-web/src/core/page-layout/sidebar-menu.ts # frontend-web/src/core/system-settings/api.ts # frontend-web/src/core/system-settings/hooks.ts # frontend-web/src/strategy-components/Header.tsx # offline-backend-20260512/backend/CLAUDE.md # offline-backend-20260512/backend/app/gateway/routers/system_settings.py # offline-backend-20260512/backend/packages/harness/deerflow/config/system_settings.py # offline-backend-20260512/backend/scripts/sql/column_additions_mysql.sql
This commit is contained in:
commit
b380575f16
103 files changed
+5915
-859
No files matched your search
+50
@@ -0,0 +1,50 @@
|
||||
"""Add seat_mode column to roundtable_chains.
|
||||
|
||||
Per-chain「默认席位执行模式」: an optional short string (flash/thinking/pro/ultra, see
|
||||
frontend ``lib/seat-mode.ts``) the user picks in the chain editor. When the chain is
|
||||
selected into a roundtable discussion the picker defaults to it (still overridable per
|
||||
run). NULL = unset → callers fall back to the default (pro). VARCHAR(16) on MySQL, plain
|
||||
String elsewhere — matching ``String(16)`` on ``RoundtableChainRow.seat_mode``.
|
||||
|
||||
``create_all`` adds the column for brand-new DBs; the startup ``_ensure_orm_columns_sync``
|
||||
sweep adds it to already-existing tables (sqlite/mysql/postgres). This revision keeps the
|
||||
alembic graph consistent with the rest of the chain columns and documents the change.
|
||||
|
||||
Revision ID: 20260615_01
|
||||
Revises: 20260612_01
|
||||
Create Date: 2026-06-15
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
|
||||
|
||||
revision = "20260615_01"
|
||||
down_revision = "20260612_01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def _has_table(table_name: str) -> bool:
|
||||
inspector = inspect(op.get_bind())
|
||||
return table_name in inspector.get_table_names()
|
||||
|
||||
|
||||
def _has_column(table_name: str, column_name: str) -> bool:
|
||||
if not _has_table(table_name):
|
||||
return False
|
||||
inspector = inspect(op.get_bind())
|
||||
return any(col["name"] == column_name for col in inspector.get_columns(table_name))
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if _has_table("roundtable_chains") and not _has_column("roundtable_chains", "seat_mode"):
|
||||
op.add_column("roundtable_chains", sa.Column("seat_mode", sa.String(length=16), nullable=True))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if _has_column("roundtable_chains", "seat_mode"):
|
||||
op.drop_column("roundtable_chains", "seat_mode")
|
||||
+2
@@ -45,6 +45,7 @@ from deerflow.persistence.notifications.model import NotificationRow
|
||||
from deerflow.persistence.parallel_agent_tasks.model import ParallelAgentTaskRow
|
||||
from deerflow.persistence.positions.model import PositionRow, PositionTagBindingRow
|
||||
from deerflow.persistence.recommended_questions.model import RecommendedQuestionRow
|
||||
from deerflow.persistence.research_templates.model import ResearchTemplateRow
|
||||
from deerflow.persistence.roundtable_chains.model import RoundtableChainRow
|
||||
from deerflow.persistence.roundtable_draft_shares.model import RoundtableDraftShareRow
|
||||
from deerflow.persistence.roundtable_drafts.model import (
|
||||
@@ -96,6 +97,7 @@ __all__ = [
|
||||
"PositionRow",
|
||||
"PositionTagBindingRow",
|
||||
"RecommendedQuestionRow",
|
||||
"ResearchTemplateRow",
|
||||
"RoundtableChainRow",
|
||||
"RoundtableDraftRow",
|
||||
"RoundtableDraftShareRow",
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
from deerflow.persistence.research_templates.model import ResearchTemplateRow
|
||||
from deerflow.persistence.research_templates.sql import ResearchTemplateRepository
|
||||
|
||||
|
||||
def make_research_template_store(session_factory) -> ResearchTemplateRepository | None:
|
||||
if session_factory is None:
|
||||
return None
|
||||
return ResearchTemplateRepository(session_factory)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"ResearchTemplateRow",
|
||||
"ResearchTemplateRepository",
|
||||
"make_research_template_store",
|
||||
]
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
"""ORM model for AI writing research templates (课题研究模板).
|
||||
|
||||
A research template bundles a set of writing-form presets — article type,
|
||||
outline, material source, word count, audience, strict mode and a topic/intent —
|
||||
so a user can one-click pre-fill the whole 课题研究 form. Maintained from the
|
||||
research-template config page (需求 0616 #5).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from sqlalchemy import Boolean, DateTime, Integer, String, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from deerflow.persistence.base import Base
|
||||
|
||||
|
||||
class ResearchTemplateRow(Base):
|
||||
__tablename__ = "ai_writing_research_templates"
|
||||
|
||||
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
||||
name: Mapped[str] = mapped_column(String(128), nullable=False)
|
||||
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
# 预设字段(点击模板时回填表单)。
|
||||
article_type_key: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
outline: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
material_source: Mapped[str] = mapped_column(String(32), nullable=False, default="general")
|
||||
word_count: Mapped[int] = mapped_column(Integer, nullable=False, default=800)
|
||||
audience: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
||||
strict_mode: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||||
topic: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
sort_order: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=lambda: datetime.now(UTC))
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=lambda: datetime.now(UTC))
|
||||
+221
@@ -0,0 +1,221 @@
|
||||
"""SQLAlchemy-backed research template storage."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
|
||||
|
||||
from deerflow.persistence.research_templates.model import ResearchTemplateRow
|
||||
|
||||
_UNSET = object()
|
||||
|
||||
|
||||
# 新机器内置范例模板(表为空时由 seed_defaults() 写入;作为给用户的范例,内容务求规范好用)。
|
||||
# article_type_key 取自默认文章类型(news/analysis/feature/report,见 20260517_02 迁移)。
|
||||
DEFAULT_RESEARCH_TEMPLATES: list[dict] = [
|
||||
{
|
||||
"name": "网摘",
|
||||
"description": "汇编近期网络热点信息,分条摘录核心要点并标注来源,快速掌握全貌",
|
||||
"article_type_key": "news",
|
||||
"material_source": "general",
|
||||
"word_count": 1000,
|
||||
"audience": "关注热点动态的一般读者",
|
||||
"strict_mode": False,
|
||||
"topic": (
|
||||
"围绕【主题】检索并汇编近一周网络上的重要信息与热点动态,"
|
||||
"逐条摘录核心事实、关键数据与原文出处,帮助读者快速掌握全貌。"
|
||||
),
|
||||
"outline": (
|
||||
"一、热点速览(用一句话清单列出本期要点)\n"
|
||||
"二、重点摘录\n"
|
||||
" 1.【事件/话题标题】——核心事实、关键数据、信息来源\n"
|
||||
" 2.【事件/话题标题】——……\n"
|
||||
" 3.(按重要性依次罗列)\n"
|
||||
"三、关联动态与背景补充(串联相关信息、补足来龙去脉)\n"
|
||||
"四、小结与观察(提炼趋势或值得关注的看点)"
|
||||
),
|
||||
"sort_order": 0,
|
||||
},
|
||||
{
|
||||
"name": "周报",
|
||||
"description": "按周梳理工作进展、数据指标与问题风险,输出结构化周度汇报",
|
||||
"article_type_key": "report",
|
||||
"material_source": "general",
|
||||
"word_count": 1200,
|
||||
"audience": "团队成员与上级主管",
|
||||
"strict_mode": True,
|
||||
"topic": (
|
||||
"汇总本周【项目/团队】的工作进展,撰写周报:"
|
||||
"覆盖关键成果、数据指标、问题风险与下周计划,简明、客观、可量化。"
|
||||
),
|
||||
"outline": (
|
||||
"一、本周概览(一句话总结 + 关键指标对比上周)\n"
|
||||
"二、重点进展\n"
|
||||
" 1. 已完成事项与成果(结论先行,附支撑数据)\n"
|
||||
" 2. 关键数据 / 里程碑达成情况\n"
|
||||
"三、问题与风险(逐条列出问题、影响面及应对措施)\n"
|
||||
"四、下周计划与资源需求(目标、负责人、所需支持)"
|
||||
),
|
||||
"sort_order": 1,
|
||||
},
|
||||
{
|
||||
"name": "要讯",
|
||||
"description": "提炼最重要的资讯,精炼成简报式要点,突出核心事实与潜在影响",
|
||||
"article_type_key": "analysis",
|
||||
"material_source": "general",
|
||||
"word_count": 600,
|
||||
"audience": "需快速掌握要点的决策者",
|
||||
"strict_mode": True,
|
||||
"topic": (
|
||||
"围绕【主题/领域】提炼近期最重要的资讯,编写要讯:"
|
||||
"每条聚焦核心事实、关键背景与潜在影响,文字精炼、判断审慎。"
|
||||
),
|
||||
"outline": (
|
||||
"一、头条要讯(1–3 条,每条用一句话点明核心)\n"
|
||||
"二、要点详述(逐条展开)\n"
|
||||
" · 事实:发生了什么、何时何地、涉及谁\n"
|
||||
" · 背景:为何重要、与既有态势的关系\n"
|
||||
" · 影响:可能带来的后果与连锁反应\n"
|
||||
"三、研判与建议(给出倾向性判断与可行动建议)"
|
||||
),
|
||||
"sort_order": 2,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
class ResearchTemplateRepository:
|
||||
def __init__(self, session_factory: async_sessionmaker[AsyncSession]) -> None:
|
||||
self._sf = session_factory
|
||||
|
||||
@staticmethod
|
||||
def _row_to_dict(row: ResearchTemplateRow) -> dict:
|
||||
d = row.to_dict()
|
||||
for k in ("created_at", "updated_at"):
|
||||
if isinstance(d.get(k), datetime):
|
||||
d[k] = d[k].isoformat()
|
||||
return d
|
||||
|
||||
async def create(
|
||||
self,
|
||||
*,
|
||||
name: str,
|
||||
description: str | None = None,
|
||||
article_type_key: str | None = None,
|
||||
outline: str | None = None,
|
||||
material_source: str = "general",
|
||||
word_count: int = 800,
|
||||
audience: str | None = None,
|
||||
strict_mode: bool = False,
|
||||
topic: str | None = None,
|
||||
sort_order: int = 0,
|
||||
) -> dict:
|
||||
now = datetime.now(UTC)
|
||||
row = ResearchTemplateRow(
|
||||
id=str(uuid.uuid4()),
|
||||
name=name,
|
||||
description=description,
|
||||
article_type_key=article_type_key,
|
||||
outline=outline,
|
||||
material_source=material_source,
|
||||
word_count=word_count,
|
||||
audience=audience,
|
||||
strict_mode=strict_mode,
|
||||
topic=topic,
|
||||
sort_order=sort_order,
|
||||
created_at=now,
|
||||
updated_at=now,
|
||||
)
|
||||
async with self._sf() as session:
|
||||
session.add(row)
|
||||
await session.commit()
|
||||
await session.refresh(row)
|
||||
return self._row_to_dict(row)
|
||||
|
||||
async def update(
|
||||
self,
|
||||
template_id: str,
|
||||
*,
|
||||
name=_UNSET,
|
||||
description=_UNSET,
|
||||
article_type_key=_UNSET,
|
||||
outline=_UNSET,
|
||||
material_source=_UNSET,
|
||||
word_count=_UNSET,
|
||||
audience=_UNSET,
|
||||
strict_mode=_UNSET,
|
||||
topic=_UNSET,
|
||||
sort_order=_UNSET,
|
||||
) -> dict | None:
|
||||
async with self._sf() as session:
|
||||
row = await session.get(ResearchTemplateRow, template_id)
|
||||
if row is None:
|
||||
return None
|
||||
if name is not _UNSET:
|
||||
row.name = name
|
||||
if description is not _UNSET:
|
||||
row.description = description
|
||||
if article_type_key is not _UNSET:
|
||||
row.article_type_key = article_type_key
|
||||
if outline is not _UNSET:
|
||||
row.outline = outline
|
||||
if material_source is not _UNSET:
|
||||
row.material_source = material_source
|
||||
if word_count is not _UNSET:
|
||||
row.word_count = word_count
|
||||
if audience is not _UNSET:
|
||||
row.audience = audience
|
||||
if strict_mode is not _UNSET:
|
||||
row.strict_mode = strict_mode
|
||||
if topic is not _UNSET:
|
||||
row.topic = topic
|
||||
if sort_order is not _UNSET:
|
||||
row.sort_order = sort_order
|
||||
row.updated_at = datetime.now(UTC)
|
||||
await session.commit()
|
||||
await session.refresh(row)
|
||||
return self._row_to_dict(row)
|
||||
|
||||
async def get(self, template_id: str) -> dict | None:
|
||||
async with self._sf() as session:
|
||||
row = await session.get(ResearchTemplateRow, template_id)
|
||||
if row is None:
|
||||
return None
|
||||
return self._row_to_dict(row)
|
||||
|
||||
async def list(self) -> list[dict]:
|
||||
stmt = select(ResearchTemplateRow).order_by(
|
||||
ResearchTemplateRow.sort_order.asc(), ResearchTemplateRow.created_at.asc()
|
||||
)
|
||||
async with self._sf() as session:
|
||||
result = await session.execute(stmt)
|
||||
return [self._row_to_dict(r) for r in result.scalars()]
|
||||
|
||||
async def delete(self, template_id: str) -> bool:
|
||||
async with self._sf() as session:
|
||||
row = await session.get(ResearchTemplateRow, template_id)
|
||||
if row is None:
|
||||
return False
|
||||
await session.delete(row)
|
||||
await session.commit()
|
||||
return True
|
||||
|
||||
async def seed_defaults(self) -> int:
|
||||
"""新机器/空表时写入内置范例模板(网摘/周报/要讯)。
|
||||
|
||||
幂等:仅当表为空时插入;已有任何模板则跳过(避免覆盖用户配置或重复播种)。
|
||||
返回插入条数。
|
||||
"""
|
||||
async with self._sf() as session:
|
||||
existing = await session.execute(select(ResearchTemplateRow.id).limit(1))
|
||||
if existing.first() is not None:
|
||||
return 0
|
||||
now = datetime.now(UTC)
|
||||
for t in DEFAULT_RESEARCH_TEMPLATES:
|
||||
session.add(
|
||||
ResearchTemplateRow(id=str(uuid.uuid4()), created_at=now, updated_at=now, **t)
|
||||
)
|
||||
await session.commit()
|
||||
return len(DEFAULT_RESEARCH_TEMPLATES)
|
||||
+3
@@ -49,6 +49,9 @@ class RoundtableChainRow(Base):
|
||||
# 怎么派活、做什么(整体编排策略 / 风格 / 约束)。**仅分层 DAG 模式生效**:注入到总控
|
||||
# 每阶段派活提示(``buildDagStageLeaderTask``)。NULL = 不注入。纯文本,存为 LONGTEXT。
|
||||
coordinator_prompt: Mapped[str | None] = mapped_column(PortableLongText, nullable=True)
|
||||
# 可选「默认席位执行模式」:flash/thinking/pro/ultra(见前端 lib/seat-mode.ts)。选入研讨时
|
||||
# 弹窗默认用它(仍可临时改)。NULL = 未设,调用方回退默认(pro)。短串,VARCHAR(16)。
|
||||
seat_mode: Mapped[str | None] = mapped_column(String(16), nullable=True)
|
||||
# 发布开关:True = 公共(所有账号可在「公共」筛选里查看 / 选用);False = 仅本人可见。
|
||||
# 编辑 / 删除始终只限 owner;发布只是放开「查看 + 选入研讨」。索引以支持「公共」列表筛选。
|
||||
is_public: Mapped[bool] = mapped_column(
|
||||
|
||||
+6
@@ -56,6 +56,8 @@ class RoundtableChainRepository:
|
||||
"stage_goals": _loads(getattr(row, "stage_goals", None)),
|
||||
# 总控编排提示(写给总控的派活指引,dag-only);None/空 = 不注入。纯文本,不 json。
|
||||
"coordinator_prompt": getattr(row, "coordinator_prompt", None),
|
||||
# 默认席位执行模式(flash/thinking/pro/ultra);None = 未设。
|
||||
"seat_mode": getattr(row, "seat_mode", None),
|
||||
# 发布状态 + 是否本人所有(前端据此显示「公共」徽标、决定能否编辑 / 发布)。
|
||||
"is_public": bool(getattr(row, "is_public", False)),
|
||||
"is_mine": (current_user_id is None) or (row.user_id == current_user_id),
|
||||
@@ -110,6 +112,7 @@ class RoundtableChainRepository:
|
||||
stages=_dumps(data.get("stages")),
|
||||
stage_goals=_dumps(data.get("stage_goals")),
|
||||
coordinator_prompt=(data.get("coordinator_prompt") or None),
|
||||
seat_mode=(data.get("seat_mode") or None),
|
||||
is_public=bool(data.get("is_public") or False),
|
||||
created_at=now,
|
||||
updated_at=now,
|
||||
@@ -131,6 +134,7 @@ class RoundtableChainRepository:
|
||||
stages=_UNSET,
|
||||
stage_goals=_UNSET,
|
||||
coordinator_prompt=_UNSET,
|
||||
seat_mode=_UNSET,
|
||||
is_public=_UNSET,
|
||||
) -> dict[str, Any] | None:
|
||||
async with self._sf() as session:
|
||||
@@ -149,6 +153,8 @@ class RoundtableChainRepository:
|
||||
row.stage_goals = _dumps(stage_goals)
|
||||
if coordinator_prompt is not _UNSET:
|
||||
row.coordinator_prompt = coordinator_prompt or None
|
||||
if seat_mode is not _UNSET:
|
||||
row.seat_mode = seat_mode or None
|
||||
if is_public is not _UNSET and is_public is not None:
|
||||
row.is_public = bool(is_public)
|
||||
row.updated_at = datetime.now(UTC)
|
||||
|
||||
Reference in new issue
Block a user