54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
"""Fast taskId + goPath history lookup for single-agent deep-link workspaces.
|
|
|
|
Messages and execution state remain canonical LangGraph threads. This API reads
|
|
the dedicated ``task_deeplink_threads`` index and joins each hit to its thread
|
|
metadata by primary key, avoiding a global metadata JSON scan/filter.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Literal
|
|
|
|
from fastapi import APIRouter, Query, Request
|
|
from pydantic import BaseModel
|
|
|
|
from app.gateway.deps import get_task_deeplink_thread_store
|
|
from app.gateway.routers.threads import ThreadResponse
|
|
from deerflow.utils.time import coerce_iso
|
|
|
|
router = APIRouter(
|
|
prefix="/api/task-deeplink-threads",
|
|
tags=["task-deeplink-threads"],
|
|
)
|
|
|
|
|
|
class TaskDeeplinkThreadListResponse(BaseModel):
|
|
threads: list[ThreadResponse]
|
|
|
|
|
|
@router.get("", response_model=TaskDeeplinkThreadListResponse)
|
|
async def list_task_deeplink_threads(
|
|
request: Request,
|
|
task_id: str = Query(min_length=1, max_length=128),
|
|
go_path: Literal["3qfx", "rwfx", "xdfx", "b5-1"] = Query(),
|
|
limit: int = Query(default=100, ge=1, le=500),
|
|
) -> TaskDeeplinkThreadListResponse:
|
|
"""Return one shared deep-link history partition, newest first."""
|
|
|
|
store = get_task_deeplink_thread_store(request)
|
|
rows = await store.list_threads(task_id.strip(), go_path, limit=limit)
|
|
return TaskDeeplinkThreadListResponse(
|
|
threads=[
|
|
ThreadResponse(
|
|
thread_id=row["thread_id"],
|
|
status=row.get("status", "idle"),
|
|
created_at=coerce_iso(row.get("created_at", "")),
|
|
updated_at=coerce_iso(row.get("updated_at", "")),
|
|
metadata=row.get("metadata", {}),
|
|
values=row.get("values", {}),
|
|
interrupts=row.get("interrupts", {}),
|
|
)
|
|
for row in rows
|
|
]
|
|
)
|