feat: 工具系统迁移 + 重型插件骨架 + 前端交互增强

- 工具系统从 kilostar/plugin/tool_plugin/ 迁移到 data/toolset/(manifest.json 声明式)
- 新增 plugin_runtime 模块:BaseOrganization / GlobalPluginManager / loader / tool_bridge
- 新增 org_task + org_task_event 表及 DAO(alembic 0009)
- 新增 /api/v1/plugin 路由(submit/status/stream/install/reload)
- 新增 data/plugin/example_dept 示例重型插件
- regulatory_node 支持聊天历史上下文注入
- send_file 改为 artifact 存盘 + SSE 推送下载链接
- 前端 WorkflowFileCard 组件 + ToolSettings README 渲染
- utils 整理:合并 access/role_check、standalone_proxy→ray_compat、删除废弃模块
- 项目结构文档移至 docs/STRUCTURE.md 并详细展开

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-17 05:20:00 +00:00
parent 9b73ae4db4
commit 6d658b4f4d
74 changed files with 2591 additions and 1308 deletions
+61 -2
View File
@@ -16,14 +16,15 @@ from __future__ import annotations
import os
from datetime import datetime, timedelta, timezone
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING, Annotated, Optional
import jwt
from fastapi import HTTPException, Request, status
from fastapi import Depends, HTTPException, Request, status
from pydantic import BaseModel, ValidationError
from pwdlib import PasswordHash
if TYPE_CHECKING:
from kilostar.core.postgres_database.model import UserAuthority
from kilostar.core.postgres_database.model.user import User
@@ -174,3 +175,61 @@ class Accessor:
if not (has_alpha and has_digit):
raise ValueError("密码必须同时包含字母和数字")
return password_hasher.hash(password)
# ─── Role Check ──────────────────────────────────────────────────────────────
def _user_not_found_detail(request: Request | None = None) -> str:
from kilostar.utils.i18n import t
loc = request.headers.get("accept-language") if request else None
return t("user_not_found", accept_language=loc)
async def get_authority(user_id: str) -> "UserAuthority":
"""通过 PostgresDatabase Actor 查出指定用户的 ``UserAuthority``;用户不存在时抛 401。"""
from kilostar.utils.error import UserNotExistError
from kilostar.utils.i18n import t
from kilostar.utils.ray_hook import ray_actor_hook
postgres_database = ray_actor_hook("postgres_database").postgres_database
try:
user_authority = await postgres_database.get_user_authority.remote(
user_id=user_id
)
return user_authority
except UserNotExistError:
raise HTTPException(status_code=401, detail=t("user_not_found"))
except Exception as e:
if "UserNotExistError" in str(e):
raise HTTPException(
status_code=401, detail=t("user_not_found")
)
raise
class RoleChecker:
"""FastAPI 依赖:在路由级别按 ``UserAuthority`` 做最低权限校验。
例:``Depends(RoleChecker(allowed_roles=UserAuthority.ADMINISTRATOR))``。
"""
def __init__(self, **kwargs):
self.allowed_roles = kwargs.get(
"allowed_roles",
)
async def __call__(
self, token_data: Annotated[TokenData, Depends(Accessor.get_current_user)]
):
"""对当前请求执行权限比较,权限不足抛 403,否则把 ``TokenData`` 透传给路由。"""
user_authority = await get_authority(token_data.user_id)
if user_authority < self.allowed_roles:
raise HTTPException(
status_code=403,
detail={
"message": f"User {token_data.user_id} does not have allowed roles"
},
)
return token_data