add history endpoint

This commit is contained in:
fedorkobylkevitch 2026-04-22 15:08:27 +03:00
parent 50589232d6
commit fb7ab50de6
7 changed files with 206 additions and 6 deletions

View file

@ -59,6 +59,7 @@ class TaskService:
raw_response=raw,
error=None,
result=raw.get("result") if isinstance(raw, dict) else None,
history=self._extract_history(raw),
)
except asyncio.TimeoutError:
await self._store.set_done(
@ -66,6 +67,7 @@ class TaskService:
success=False,
raw_response=None,
error="Timeout exceeded",
history=None,
)
except BrowserRpcError as exc:
await self._store.set_done(
@ -73,6 +75,7 @@ class TaskService:
success=False,
raw_response=None,
error=str(exc),
history=None,
)
except Exception as exc:
await self._store.set_done(
@ -80,4 +83,21 @@ class TaskService:
success=False,
raw_response=None,
error=f"Internal error: {exc}",
history=None,
)
@staticmethod
def _extract_history(raw: dict | None) -> list[dict]:
if not isinstance(raw, dict):
return []
events = raw.get("history")
if not isinstance(events, list):
return []
normalized: list[dict] = []
for event in events:
if isinstance(event, dict):
normalized.append(event)
return normalized