sync update from LAN repo (source dhk-1 @ 3b1ec5b4)
This commit is contained in:
1 parent
da6521b6cb
commit
264e2200d6
995 files changed
+148105
-13399
No files matched your search
+9
-1
@@ -15,7 +15,7 @@ from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from sqlalchemy import String
|
||||
from sqlalchemy import Index, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from deerflow.persistence.base import Base
|
||||
@@ -24,6 +24,14 @@ from deerflow.persistence.types import BeijingDateTime, PortableLongText
|
||||
|
||||
class ParallelAgentTaskRow(Base):
|
||||
__tablename__ = "parallel_agent_tasks"
|
||||
__table_args__ = (
|
||||
Index(
|
||||
"ix_parallel_agent_tasks_user_updated_id",
|
||||
"user_id",
|
||||
"updated_at",
|
||||
"id",
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
||||
user_id: Mapped[str] = mapped_column(String(64), nullable=False, index=True)
|
||||
|
||||
+41
-12
@@ -11,6 +11,7 @@ that belongs to another user is treated as not found.
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from collections.abc import Mapping
|
||||
from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
|
||||
@@ -44,17 +45,32 @@ class ParallelAgentTaskRepository:
|
||||
self._sf = session_factory
|
||||
|
||||
@staticmethod
|
||||
def _to_dict(row: ParallelAgentTaskRow, *, with_messages: bool = True) -> dict[str, Any]:
|
||||
def _to_dict(
|
||||
row: ParallelAgentTaskRow | Mapping[str, Any],
|
||||
*,
|
||||
with_messages: bool = True,
|
||||
) -> dict[str, Any]:
|
||||
def value(name: str) -> Any:
|
||||
if isinstance(row, Mapping):
|
||||
return row[name]
|
||||
return getattr(row, name)
|
||||
|
||||
created_at = value("created_at")
|
||||
updated_at = value("updated_at")
|
||||
data: dict[str, Any] = {
|
||||
"id": row.id,
|
||||
"title": row.title,
|
||||
"brief": row.brief,
|
||||
"agents": _loads(row.agents) or [],
|
||||
"created_at": row.created_at.isoformat() if isinstance(row.created_at, datetime) else row.created_at,
|
||||
"updated_at": row.updated_at.isoformat() if isinstance(row.updated_at, datetime) else row.updated_at,
|
||||
"id": value("id"),
|
||||
"title": value("title"),
|
||||
"brief": value("brief"),
|
||||
"agents": _loads(value("agents")) or [],
|
||||
"created_at": (
|
||||
created_at.isoformat() if isinstance(created_at, datetime) else created_at
|
||||
),
|
||||
"updated_at": (
|
||||
updated_at.isoformat() if isinstance(updated_at, datetime) else updated_at
|
||||
),
|
||||
}
|
||||
if with_messages:
|
||||
data["messages"] = _loads(row.messages) or []
|
||||
data["messages"] = _loads(value("messages")) or []
|
||||
return data
|
||||
|
||||
async def list_tasks(
|
||||
@@ -74,9 +90,22 @@ class ParallelAgentTaskRepository:
|
||||
and ``offset`` allow those projections to page only their own task
|
||||
namespace without loading unrelated, potentially large transcripts.
|
||||
"""
|
||||
stmt = select(ParallelAgentTaskRow).where(ParallelAgentTaskRow.user_id == user_id)
|
||||
# History/list callers only need the summary columns. In particular,
|
||||
# never select the LONGTEXT transcript column unless explicitly asked:
|
||||
# MySQL otherwise reads and transfers it even though _to_dict omits it.
|
||||
columns = [
|
||||
ParallelAgentTaskRow.id,
|
||||
ParallelAgentTaskRow.title,
|
||||
ParallelAgentTaskRow.brief,
|
||||
ParallelAgentTaskRow.agents,
|
||||
ParallelAgentTaskRow.created_at,
|
||||
ParallelAgentTaskRow.updated_at,
|
||||
]
|
||||
if include_messages:
|
||||
columns.append(ParallelAgentTaskRow.messages)
|
||||
stmt = select(*columns).where(ParallelAgentTaskRow.user_id == user_id)
|
||||
if id_prefix:
|
||||
stmt = stmt.where(ParallelAgentTaskRow.id.startswith(id_prefix))
|
||||
stmt = stmt.where(ParallelAgentTaskRow.id.startswith(id_prefix, autoescape=True))
|
||||
stmt = (
|
||||
stmt.order_by(
|
||||
ParallelAgentTaskRow.updated_at.desc(),
|
||||
@@ -88,8 +117,8 @@ class ParallelAgentTaskRepository:
|
||||
async with self._sf() as session:
|
||||
result = await session.execute(stmt)
|
||||
return [
|
||||
self._to_dict(row, with_messages=include_messages)
|
||||
for row in result.scalars()
|
||||
self._to_dict(row._mapping, with_messages=include_messages)
|
||||
for row in result
|
||||
]
|
||||
|
||||
async def get_task(self, task_id: str, user_id: str) -> dict[str, Any] | None:
|
||||
|
||||
Reference in new issue
Block a user