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
@@ -13,10 +13,13 @@ from fastapi.responses import FileResponse, PlainTextResponse, Response
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from app.gateway.authz import require_permission
|
||||
from app.gateway.operation_timing import OperationTiming
|
||||
from app.gateway.path_utils import aresolve_thread_virtual_path
|
||||
from app.gateway.utils import sanitize_log_param
|
||||
from deerflow.config.paths import get_paths
|
||||
from deerflow.runtime.thread_paths import aresolve_path_user_id
|
||||
from deerflow.runtime.user_context import get_effective_user_id
|
||||
from deerflow.utils.file_io import file_io
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -535,7 +538,7 @@ async def _scan_artifact_library(
|
||||
user_id=path_user_id,
|
||||
)
|
||||
scan_errors: list[str] = []
|
||||
files = await asyncio.to_thread(
|
||||
files = await file_io(
|
||||
collect_outputs_listing,
|
||||
outputs_dir,
|
||||
errors=scan_errors,
|
||||
@@ -851,7 +854,7 @@ async def download_strategy_project_artifact(project_id: str, request: Request)
|
||||
description="List all files under the thread's outputs directory (/mnt/user-data/outputs/). Returns an empty list if the thread has no outputs.",
|
||||
)
|
||||
@require_permission("threads", "read", owner_check=True)
|
||||
async def list_artifacts(thread_id: str, request: Request) -> dict:
|
||||
async def list_artifacts(thread_id: str, request: Request, response: Response = None) -> dict: # type: ignore[assignment]
|
||||
"""列出 thread 在 ``outputs/`` 下生成的产物文件。
|
||||
|
||||
圆桌 Step 3(``HighFidelityReport``)对每个**子席位** thread_id 调用本接口,
|
||||
@@ -865,8 +868,24 @@ async def list_artifacts(thread_id: str, request: Request) -> dict:
|
||||
返回 ``{ "thread_id", "files": [{ path, name, size_bytes, mime_type, modified_at }] }``,
|
||||
目录不存在时 ``files`` 为空数组(非 404)。
|
||||
"""
|
||||
outputs_dir = get_paths().sandbox_outputs_dir(thread_id, user_id=await aresolve_path_user_id(thread_id))
|
||||
return {"thread_id": thread_id, "files": collect_outputs_listing(outputs_dir)}
|
||||
with OperationTiming(
|
||||
response,
|
||||
logger,
|
||||
"thread_artifacts",
|
||||
thread_id=sanitize_log_param(thread_id),
|
||||
) as timing:
|
||||
with timing.phase("owner_resolve"):
|
||||
user_id = await aresolve_path_user_id(thread_id)
|
||||
outputs_dir = get_paths().sandbox_outputs_dir(thread_id, user_id=user_id)
|
||||
# Probe outside the shared artifact-files pool so a background library
|
||||
# scan cannot stall an empty hello-chat listing for several seconds.
|
||||
with timing.phase("dir_probe"):
|
||||
exists = await asyncio.to_thread(lambda: outputs_dir.exists() and outputs_dir.is_dir())
|
||||
if not exists:
|
||||
return {"thread_id": thread_id, "files": []}
|
||||
with timing.phase("dir_scan"):
|
||||
files = await file_io(collect_outputs_listing, outputs_dir)
|
||||
return {"thread_id": thread_id, "files": files}
|
||||
|
||||
|
||||
def _read_bounded_text_prefix(path: Path, max_chars: int) -> tuple[str, bool]:
|
||||
@@ -922,7 +941,7 @@ async def preview_artifact(
|
||||
raise HTTPException(status_code=404, detail=f"Artifact not found: {path}")
|
||||
if not actual_path.is_file():
|
||||
raise HTTPException(status_code=400, detail=f"Path is not a file: {path}")
|
||||
if not await asyncio.to_thread(is_text_file_by_content, actual_path):
|
||||
if not await file_io(is_text_file_by_content, actual_path):
|
||||
raise HTTPException(status_code=415, detail="Bounded preview supports text content only")
|
||||
|
||||
from deerflow.uploads.inspection import inspect_text_file
|
||||
@@ -936,7 +955,7 @@ async def preview_artifact(
|
||||
total_bytes = actual_path.stat().st_size
|
||||
|
||||
if total_bytes >= threshold:
|
||||
report = await asyncio.to_thread(
|
||||
report = await file_io(
|
||||
inspect_text_file,
|
||||
actual_path,
|
||||
max_result_chars=effective_limit,
|
||||
@@ -953,7 +972,7 @@ async def preview_artifact(
|
||||
warnings=[str(item) for item in report.get("warnings") or []],
|
||||
)
|
||||
|
||||
content, truncated = await asyncio.to_thread(_read_bounded_text_prefix, actual_path, effective_limit)
|
||||
content, truncated = await file_io(_read_bounded_text_prefix, actual_path, effective_limit)
|
||||
warnings = ["预览达到字符上限,未读取的内容不会进入页面或模型上下文。"] if truncated else []
|
||||
return ArtifactPreviewResponse(
|
||||
path=path,
|
||||
@@ -1023,7 +1042,7 @@ async def get_artifact(thread_id: str, path: str, request: Request, download: bo
|
||||
raise HTTPException(status_code=400, detail=f"Path is not a file: {skill_file_path}")
|
||||
|
||||
# Extract the file from the .skill archive
|
||||
content = _extract_file_from_skill_archive(actual_skill_path, internal_path)
|
||||
content = await file_io(_extract_file_from_skill_archive, actual_skill_path, internal_path)
|
||||
if content is None:
|
||||
raise HTTPException(status_code=404, detail=f"File '{internal_path}' not found in skill archive")
|
||||
|
||||
@@ -1077,7 +1096,7 @@ async def get_artifact(thread_id: str, path: str, request: Request, download: bo
|
||||
headers={"Content-Disposition": _build_content_disposition("inline", actual_path.name)},
|
||||
)
|
||||
|
||||
if is_text_file_by_content(actual_path):
|
||||
if await file_io(is_text_file_by_content, actual_path):
|
||||
return FileResponse(
|
||||
path=actual_path,
|
||||
media_type=mime_type or "text/plain",
|
||||
@@ -1129,5 +1148,5 @@ async def update_artifact(
|
||||
if suffix not in EDITABLE_TEXT_SUFFIXES and not (mime_type and mime_type.startswith("text/")):
|
||||
raise HTTPException(status_code=400, detail="Only text artifacts can be edited.")
|
||||
|
||||
actual_path.write_text(body.content, encoding="utf-8")
|
||||
await file_io(actual_path.write_text, body.content, encoding="utf-8")
|
||||
return PlainTextResponse(content=body.content, media_type=mime_type or "text/plain")
|
||||
Reference in new issue
Block a user