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
@@ -31,6 +31,7 @@ from datetime import datetime
|
||||
from fastapi import APIRouter, HTTPException, Query, Request
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from app.gateway.catalog_cache import cached_catalog, catalog_key, invalidate_catalog
|
||||
from app.gateway.deps import get_current_user, get_optional_user_from_request
|
||||
from deerflow.persistence.light_apps import DuplicateLightAppNameError, LightAppStore
|
||||
|
||||
@@ -77,6 +78,17 @@ class LightAppListResponse(BaseModel):
|
||||
apps: list[LightAppResponse]
|
||||
|
||||
|
||||
class LightAppSidebarItem(BaseModel):
|
||||
app_id: str
|
||||
name: str
|
||||
mount_location: str | None = None
|
||||
sort_order: int = 0
|
||||
|
||||
|
||||
class LightAppSidebarResponse(BaseModel):
|
||||
apps: list[LightAppSidebarItem]
|
||||
|
||||
|
||||
class LightAppCreateRequest(BaseModel):
|
||||
name: str = Field(..., min_length=1, max_length=127)
|
||||
description: str | None = Field(default=None, max_length=1000)
|
||||
@@ -167,15 +179,34 @@ async def list_light_apps(
|
||||
tag_ids: list[str] | None = Query(default=None, description="Keep apps carrying any of these tags (OR)"),
|
||||
) -> LightAppListResponse:
|
||||
store = _get_store(request)
|
||||
rows = await store.list_apps(app_type=app_type, mount_location=mount_location, enabled_only=enabled_only)
|
||||
if search:
|
||||
needle = search.strip().lower()
|
||||
rows = [r for r in rows if needle in str(r.get("name", "")).lower() or needle in str(r.get("description") or "").lower()]
|
||||
responses = await _attach_tags(request, [LightAppResponse(**r) for r in rows])
|
||||
if tag_ids:
|
||||
wanted = set(tag_ids)
|
||||
responses = [r for r in responses if any(t.get("id") in wanted for t in r.tags)]
|
||||
return LightAppListResponse(apps=responses)
|
||||
|
||||
async def load() -> LightAppListResponse:
|
||||
rows = await store.list_apps(app_type=app_type, mount_location=mount_location, enabled_only=enabled_only)
|
||||
if search:
|
||||
needle = search.strip().lower()
|
||||
rows = [r for r in rows if needle in str(r.get("name", "")).lower() or needle in str(r.get("description") or "").lower()]
|
||||
responses = await _attach_tags(request, [LightAppResponse(**r) for r in rows])
|
||||
if tag_ids:
|
||||
wanted = set(tag_ids)
|
||||
responses = [r for r in responses if any(t.get("id") in wanted for t in r.tags)]
|
||||
return LightAppListResponse(apps=responses)
|
||||
|
||||
return await cached_catalog(
|
||||
request, "light_apps", catalog_key("list", app_type, mount_location, enabled_only, search, sorted(tag_ids or [])),
|
||||
load, LightAppListResponse,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/sidebar", response_model=LightAppSidebarResponse)
|
||||
async def list_sidebar_light_apps(request: Request) -> LightAppSidebarResponse:
|
||||
"""Return the small set of fields required to build the shared sidebar."""
|
||||
store = _get_store(request)
|
||||
|
||||
async def load() -> LightAppSidebarResponse:
|
||||
rows = await store.list_sidebar_apps()
|
||||
return LightAppSidebarResponse(apps=[LightAppSidebarItem(**row) for row in rows])
|
||||
|
||||
return await cached_catalog(request, "light_apps", "sidebar", load, LightAppSidebarResponse)
|
||||
|
||||
|
||||
@router.post("", response_model=LightAppResponse)
|
||||
@@ -201,6 +232,7 @@ async def create_light_app(request: Request, body: LightAppCreateRequest) -> Lig
|
||||
)
|
||||
except DuplicateLightAppNameError:
|
||||
raise HTTPException(status_code=409, detail="应用名称已存在")
|
||||
await invalidate_catalog(request, "light_apps")
|
||||
attached = await _attach_tags(request, [LightAppResponse(**row)])
|
||||
return attached[0]
|
||||
|
||||
@@ -208,11 +240,15 @@ async def create_light_app(request: Request, body: LightAppCreateRequest) -> Lig
|
||||
@router.get("/{app_id}", response_model=LightAppResponse)
|
||||
async def get_light_app(request: Request, app_id: str) -> LightAppResponse:
|
||||
store = _get_store(request)
|
||||
row = await store.get_app(app_id)
|
||||
if row is None:
|
||||
raise HTTPException(status_code=404, detail="应用不存在")
|
||||
attached = await _attach_tags(request, [LightAppResponse(**row)])
|
||||
return attached[0]
|
||||
|
||||
async def load() -> LightAppResponse:
|
||||
row = await store.get_app(app_id)
|
||||
if row is None:
|
||||
raise HTTPException(status_code=404, detail="应用不存在")
|
||||
attached = await _attach_tags(request, [LightAppResponse(**row)])
|
||||
return attached[0]
|
||||
|
||||
return await cached_catalog(request, "light_apps", catalog_key("detail", app_id), load, LightAppResponse)
|
||||
|
||||
|
||||
@router.put("/{app_id}", response_model=LightAppResponse)
|
||||
@@ -242,6 +278,7 @@ async def update_light_app(request: Request, app_id: str, body: LightAppUpdateRe
|
||||
raise HTTPException(status_code=409, detail="应用名称已存在")
|
||||
if row is None:
|
||||
raise HTTPException(status_code=404, detail="应用不存在")
|
||||
await invalidate_catalog(request, "light_apps")
|
||||
attached = await _attach_tags(request, [LightAppResponse(**row)])
|
||||
return attached[0]
|
||||
|
||||
@@ -254,4 +291,5 @@ async def delete_light_app(request: Request, app_id: str) -> dict:
|
||||
if not deleted:
|
||||
raise HTTPException(status_code=404, detail="应用不存在")
|
||||
await _unassign_tags(request, app_id)
|
||||
await invalidate_catalog(request, "light_apps")
|
||||
return {"success": True}
|
||||
Reference in new issue
Block a user