sync update from LAN repo (source dhk-1 @ 3b1ec5b4)

This commit is contained in:
gozeros committed 2026-11-05 10:56:34 +08:00
1 parent da6521b6cb
commit 264e2200d6
995 files changed
+148105 -13399

No files matched your search

@@ -7,10 +7,21 @@ from typing import Any
class TaskDeeplinkDetailStore(ABC):
"""Shared external task snapshots keyed by ``(detail_type, detail_id)``."""
"""Shared external task snapshots keyed by ``(detail_type, detail_id, sub_type)``.
``sub_type`` is the integrator-supplied business type (the deep-link
``?type=``): the same task id may hold one snapshot per type, each with its
own version counter. The empty string is the legacy no-type partition.
"""
@abstractmethod
async def get_detail(self, detail_type: str, detail_id: str) -> dict[str, Any] | None:
async def get_detail(
self,
detail_type: str,
detail_id: str,
*,
sub_type: str = "",
) -> dict[str, Any] | None:
"""Return one persisted task snapshot, or ``None`` when it is unknown."""
raise NotImplementedError
@@ -20,6 +31,7 @@ class TaskDeeplinkDetailStore(ABC):
detail_type: str,
detail_id: str,
*,
sub_type: str = "",
task_name: str,
task_content: str,
overview: str,
@@ -11,10 +11,16 @@ from deerflow.persistence.task_deeplink_details.base import TaskDeeplinkDetailSt
class MemoryTaskDeeplinkDetailStore(TaskDeeplinkDetailStore):
def __init__(self) -> None:
self._rows: dict[tuple[str, str], dict[str, Any]] = {}
self._rows: dict[tuple[str, str, str], dict[str, Any]] = {}
async def get_detail(self, detail_type: str, detail_id: str) -> dict[str, Any] | None:
row = self._rows.get((detail_type, detail_id))
async def get_detail(
self,
detail_type: str,
detail_id: str,
*,
sub_type: str = "",
) -> dict[str, Any] | None:
row = self._rows.get((detail_type, detail_id, sub_type))
return deepcopy(row) if row is not None else None
async def upsert_detail(
@@ -22,13 +28,14 @@ class MemoryTaskDeeplinkDetailStore(TaskDeeplinkDetailStore):
detail_type: str,
detail_id: str,
*,
sub_type: str = "",
task_name: str,
task_content: str,
overview: str,
extra: dict[str, Any],
updated_by: str | None,
) -> tuple[dict[str, Any], bool, bool]:
key = (detail_type, detail_id)
key = (detail_type, detail_id, sub_type)
row = self._rows.get(key)
created = row is None
if row is None:
@@ -36,6 +43,7 @@ class MemoryTaskDeeplinkDetailStore(TaskDeeplinkDetailStore):
row = {
"detail_type": detail_type,
"detail_id": detail_id,
"sub_type": sub_type,
"version": 1,
"created_by": updated_by,
"created_at": now,
@@ -18,6 +18,9 @@ class TaskDeeplinkDetailRow(Base):
detail_type: Mapped[str] = mapped_column(String(32), primary_key=True)
detail_id: Mapped[str] = mapped_column(String(128), primary_key=True)
# Integrator-supplied business type (the deep-link ``?type=``): one task id
# may carry several typed snapshots; "" is the legacy no-type partition.
sub_type: Mapped[str] = mapped_column(String(64), primary_key=True, default="")
task_name: Mapped[str] = mapped_column(String(512), nullable=False, default="")
task_content: Mapped[str] = mapped_column(PortableLongText, nullable=False, default="")
overview: Mapped[str] = mapped_column(PortableLongText, nullable=False, default="")
@@ -15,6 +15,7 @@ def _to_dict(row: TaskDeeplinkDetailRow) -> dict[str, Any]:
return {
"detail_type": row.detail_type,
"detail_id": row.detail_id,
"sub_type": row.sub_type or "",
"task_name": row.task_name,
"task_content": row.task_content,
"overview": row.overview,
@@ -31,11 +32,17 @@ class TaskDeeplinkDetailRepository(TaskDeeplinkDetailStore):
def __init__(self, session_factory: async_sessionmaker[AsyncSession]) -> None:
self._sf = session_factory
async def get_detail(self, detail_type: str, detail_id: str) -> dict[str, Any] | None:
async def get_detail(
self,
detail_type: str,
detail_id: str,
*,
sub_type: str = "",
) -> dict[str, Any] | None:
async with self._sf() as session:
row = await session.get(
TaskDeeplinkDetailRow,
{"detail_type": detail_type, "detail_id": detail_id},
{"detail_type": detail_type, "detail_id": detail_id, "sub_type": sub_type},
)
return _to_dict(row) if row is not None else None
@@ -44,6 +51,7 @@ class TaskDeeplinkDetailRepository(TaskDeeplinkDetailStore):
detail_type: str,
detail_id: str,
*,
sub_type: str = "",
task_name: str,
task_content: str,
overview: str,
@@ -53,7 +61,7 @@ class TaskDeeplinkDetailRepository(TaskDeeplinkDetailStore):
async with self._sf() as session:
row = await session.get(
TaskDeeplinkDetailRow,
{"detail_type": detail_type, "detail_id": detail_id},
{"detail_type": detail_type, "detail_id": detail_id, "sub_type": sub_type},
)
created = row is None
now = datetime.now(UTC)
@@ -61,6 +69,7 @@ class TaskDeeplinkDetailRepository(TaskDeeplinkDetailStore):
row = TaskDeeplinkDetailRow(
detail_type=detail_type,
detail_id=detail_id,
sub_type=sub_type,
task_name=task_name,
task_content=task_content,
overview=overview,