update api for subagent protocol and delete hermes agent
This commit is contained in:
parent
ff1799cd98
commit
952b2e7d17
1150 changed files with 704 additions and 458893 deletions
0
api/mappers/__init__.py
Normal file
0
api/mappers/__init__.py
Normal file
127
api/mappers/task_record_mapper.py
Normal file
127
api/mappers/task_record_mapper.py
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from api.contracts.task_schemas import (
|
||||
BrowserTaskAcceptedResponse,
|
||||
BrowserTaskHistoryResponse,
|
||||
BrowserTaskResultResponse,
|
||||
BrowserTaskStatusResponse,
|
||||
RunListResponse,
|
||||
RunResponse,
|
||||
RunSummaryResponse,
|
||||
RunWaitResponse,
|
||||
TaskHistoryEvent,
|
||||
)
|
||||
from api.domain.task_status import TaskStatus
|
||||
from api.repositories.task_store import TaskRecord
|
||||
|
||||
|
||||
class TaskRecordMapper:
|
||||
ACTIVE_STATUSES = (TaskStatus.queued, TaskStatus.running)
|
||||
|
||||
@classmethod
|
||||
def is_active_status(cls, status: TaskStatus) -> bool:
|
||||
return status in cls.ACTIVE_STATUSES
|
||||
|
||||
@staticmethod
|
||||
def to_task_accepted(rec: TaskRecord) -> BrowserTaskAcceptedResponse:
|
||||
return BrowserTaskAcceptedResponse(task_id=rec.task_id, status=rec.status)
|
||||
|
||||
@staticmethod
|
||||
def to_task_status(rec: TaskRecord) -> BrowserTaskStatusResponse:
|
||||
return BrowserTaskStatusResponse(
|
||||
task_id=rec.task_id,
|
||||
status=rec.status,
|
||||
create_at=rec.create_at,
|
||||
started_at=rec.started_at,
|
||||
finished_at=rec.finished_at,
|
||||
error=rec.error,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def to_task_result(rec: TaskRecord) -> BrowserTaskResultResponse:
|
||||
return BrowserTaskResultResponse(
|
||||
task_id=rec.task_id,
|
||||
status=rec.status,
|
||||
success=(rec.status == TaskStatus.succeeded),
|
||||
execution_time=rec.execution_time,
|
||||
result=rec.result,
|
||||
error=rec.error,
|
||||
raw_response=rec.raw_response,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def to_pending_task_result(rec: TaskRecord) -> BrowserTaskResultResponse:
|
||||
return BrowserTaskResultResponse(
|
||||
task_id=rec.task_id,
|
||||
status=rec.status,
|
||||
success=False,
|
||||
execution_time=rec.execution_time,
|
||||
result=None,
|
||||
error=None,
|
||||
raw_response=None,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def to_history_events(raw_history: list[dict[str, Any]]) -> list[TaskHistoryEvent]:
|
||||
events: list[TaskHistoryEvent] = []
|
||||
for index, item in enumerate(raw_history, start=1):
|
||||
raw_step = item.get("step")
|
||||
step = raw_step if isinstance(raw_step, int) else index
|
||||
kind = str(item.get("kind") or item.get("type") or "system")
|
||||
content = item.get("content")
|
||||
if content is not None:
|
||||
content = str(content)
|
||||
data = item.get("data") if isinstance(item.get("data"), dict) else {}
|
||||
events.append(TaskHistoryEvent(step=step, kind=kind, content=content, data=data))
|
||||
return events
|
||||
|
||||
@classmethod
|
||||
def to_task_history(cls, rec: TaskRecord) -> BrowserTaskHistoryResponse:
|
||||
return BrowserTaskHistoryResponse(task_id=rec.task_id, status=rec.status,
|
||||
history=cls.to_history_events(rec.history))
|
||||
|
||||
@classmethod
|
||||
def to_pending_task_history(cls, rec: TaskRecord) -> BrowserTaskHistoryResponse:
|
||||
return BrowserTaskHistoryResponse(task_id=rec.task_id, status=rec.status,
|
||||
history=cls.to_history_events(rec.history))
|
||||
|
||||
@staticmethod
|
||||
def to_run_summary(rec: TaskRecord) -> RunSummaryResponse:
|
||||
return RunSummaryResponse(
|
||||
run_id=rec.task_id,
|
||||
thread_id=rec.thread_id,
|
||||
status=rec.status,
|
||||
created_at=rec.create_at,
|
||||
started_at=rec.started_at,
|
||||
finished_at=rec.finished_at,
|
||||
error=rec.error,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def to_run_response(cls, rec: TaskRecord) -> RunResponse:
|
||||
return RunResponse.model_validate(
|
||||
{
|
||||
"run_id": rec.task_id,
|
||||
"thread_id": rec.thread_id,
|
||||
"status": rec.status,
|
||||
"created_at": rec.create_at,
|
||||
"started_at": rec.started_at,
|
||||
"finished_at": rec.finished_at,
|
||||
"error": rec.error,
|
||||
"input": rec.task,
|
||||
"metadata": rec.metadata,
|
||||
"output": rec.result,
|
||||
"raw_response": rec.raw_response,
|
||||
"history": cls.to_history_events(rec.history),
|
||||
}
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def to_run_wait(cls, rec: TaskRecord) -> RunWaitResponse:
|
||||
return RunWaitResponse(run=cls.to_run_response(rec))
|
||||
|
||||
@classmethod
|
||||
def to_thread_run_list(cls, thread_id: str, runs: list[TaskRecord]) -> RunListResponse:
|
||||
return RunListResponse(thread_id=thread_id, runs=[cls.to_run_summary(item) for item in runs])
|
||||
Loading…
Add table
Add a link
Reference in a new issue