feat: 工具/技能调用统计 + 用户活动审计 + 标签多选筛选
- 任务1: 用户管理/定时任务管理移入左下角菜单, 从侧边栏删除原入口
- 任务2: 管理员查看用户问答(读 LangGraph checkpoint)与记忆, 新增 admin_users 路由与审计页
- 任务3: 标签筛选改为顶部多选标签栏(OR), agents/skills/scheduled_tasks 三端
- 任务4: 新增 tool_call_metrics 表 + ToolMetricsMiddleware + tool-metrics 路由,
工具/技能调用统计并入大模型统计页, 含错误分类
- 技能识别: lead agent 经 read_file 加载 /mnt/skills/<cat>/<name>/SKILL.md 调用技能,
中间件扫描工具参数里的 skills/{public,custom}/{name}/ 路径还原 skill_name
- 单元测试 tests/test_tool_metrics_middleware.py (18 项全过)
- 附: SQLite->MySQL 切换后清理脚本
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e3cde9be25
commit
4940e0d8ed
46 files changed
+3299
-315
No files matched your search
@@ -294,20 +294,38 @@ async def get_public_share_snapshot(
|
||||
)
|
||||
|
||||
|
||||
# Content types that can execute scripts in the app origin — always served as
|
||||
# a download attachment so a shared file can never run as a top-level document.
|
||||
_PUBLIC_SHARE_ACTIVE_TYPES = {"text/html", "application/xhtml+xml", "image/svg+xml"}
|
||||
|
||||
|
||||
def _public_share_disposition(mime_type: str) -> str:
|
||||
"""Pick a Content-Disposition for a public-share file.
|
||||
|
||||
Active content (HTML/XHTML/SVG) is forced to ``attachment`` so it cannot
|
||||
execute as a top-level document; everything else (images, Markdown, text,
|
||||
PDF, …) is served ``inline`` so viewers can open it directly.
|
||||
"""
|
||||
return "attachment" if mime_type in _PUBLIC_SHARE_ACTIVE_TYPES else "inline"
|
||||
|
||||
|
||||
@public_router.get(
|
||||
"/{share_code}/files/{path:path}",
|
||||
summary="Public image attachment from a view-shared conversation",
|
||||
summary="Public file attachment from a view-shared conversation",
|
||||
)
|
||||
async def get_public_share_file(
|
||||
share_code: str,
|
||||
path: str,
|
||||
share_store: ThreadShareStore = Depends(get_thread_share_store),
|
||||
) -> FileResponse:
|
||||
"""Serve an image referenced by a view-shared conversation.
|
||||
"""Serve a file referenced by a view-shared conversation.
|
||||
|
||||
Restricted to images only — the public share page renders inline images,
|
||||
but the endpoint must not become a way to read arbitrary thread files.
|
||||
Non-image paths return 404 just like a missing file.
|
||||
A ``view`` share is a public read-only page, so the files its conversation
|
||||
references (images, Markdown, text, PDF, …) must be openable. Path
|
||||
resolution is confined to the owner's thread directory, so this cannot read
|
||||
arbitrary files. Active content (HTML/XHTML/SVG) is forced to download so it
|
||||
can never execute as a top-level document in the app origin; everything
|
||||
else is served inline.
|
||||
"""
|
||||
share = await share_store.get(share_code)
|
||||
if share is None or share.get("revoked") or share.get("mode") != "view":
|
||||
@@ -324,17 +342,10 @@ async def get_public_share_file(
|
||||
if not actual_path.exists() or not actual_path.is_file():
|
||||
raise HTTPException(status_code=404, detail="File not found")
|
||||
|
||||
mime_type, _ = mimetypes.guess_type(actual_path.name)
|
||||
if not mime_type or not mime_type.startswith("image/"):
|
||||
# Only images are public; everything else is treated as not found.
|
||||
raise HTTPException(status_code=404, detail="File not found")
|
||||
|
||||
# SVG can carry scripts — serve it as a download so it can never execute
|
||||
# as a top-level document in the app origin. Raster images render inline.
|
||||
is_svg = mime_type == "image/svg+xml"
|
||||
mime_type = mimetypes.guess_type(actual_path.name)[0] or "application/octet-stream"
|
||||
return FileResponse(
|
||||
actual_path,
|
||||
media_type=mime_type,
|
||||
content_disposition_type="attachment" if is_svg else "inline",
|
||||
content_disposition_type=_public_share_disposition(mime_type),
|
||||
headers={"Cache-Control": "public, max-age=300"},
|
||||
)
|
||||
Reference in new issue
Block a user