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
+22
-3
@@ -11,10 +11,15 @@ When user_id is None, no user filtering is applied (single-user mode).
|
||||
from __future__ import annotations
|
||||
|
||||
import abc
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
|
||||
class RunStore(abc.ABC):
|
||||
async def update_snapshot(self, run_id: str, *, metadata: dict, kwargs: dict) -> bool:
|
||||
"""Persist late metadata before retiring the live registry copy."""
|
||||
return False
|
||||
|
||||
@abc.abstractmethod
|
||||
async def put(
|
||||
self,
|
||||
@@ -33,7 +38,7 @@ class RunStore(abc.ABC):
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
async def get(self, run_id: str) -> dict[str, Any] | None:
|
||||
async def get(self, run_id: str, *, user_id=None) -> dict[str, Any] | None:
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
@@ -94,11 +99,25 @@ class RunStore(abc.ABC):
|
||||
"""
|
||||
pass
|
||||
|
||||
async def count_by_user(self) -> dict[str, int]:
|
||||
"""Return ``{user_id: run_count}`` across all runs.
|
||||
async def count_by_user(self, *, since: datetime | None = None) -> dict[str, int]:
|
||||
"""Return ``{user_id: run_count}``, optionally from ``since`` onward.
|
||||
|
||||
One run corresponds to one user submission, so this backs the admin
|
||||
user center's 问答次数 (Q&A count) column — each question counts once.
|
||||
Non-overriding stores return an empty mapping (treated as 0 per user).
|
||||
"""
|
||||
return {}
|
||||
|
||||
async def purge_terminal_before(
|
||||
self,
|
||||
cutoff: datetime,
|
||||
*,
|
||||
batch_size: int = 500,
|
||||
) -> int:
|
||||
"""Delete one bounded batch of expired terminal run summaries.
|
||||
|
||||
A run summary is operational audit metadata (including the compact
|
||||
first-question / last-answer fields), not the user's conversation
|
||||
checkpoint. The default keeps memory and alternate stores compatible.
|
||||
"""
|
||||
return 0
|
||||
+7
-1
@@ -44,8 +44,14 @@ class MemoryRunStore(RunStore):
|
||||
"updated_at": now,
|
||||
}
|
||||
|
||||
async def get(self, run_id):
|
||||
async def get(self, run_id, *, user_id=None):
|
||||
return self._runs.get(run_id)
|
||||
|
||||
async def update_snapshot(self, run_id, *, metadata, kwargs):
|
||||
if run_id not in self._runs:
|
||||
return False
|
||||
self._runs[run_id].update(metadata=metadata, kwargs=kwargs)
|
||||
return True
|
||||
|
||||
async def list_by_thread(self, thread_id, *, user_id=None, limit=100):
|
||||
results = [r for r in self._runs.values() if r["thread_id"] == thread_id and (user_id is None or r.get("user_id") == user_id)]
|
||||
|
||||
Reference in new issue
Block a user