feat(plugin_system): 引入插件HTTP端点系统
引入了全新的 `BaseRouterComponent` 组件类型,允许插件开发者通过继承并实现 `register_endpoints` 方法来创建 FastAPI 路由。 - 插件系统现在可以自动发现并注册这些路由组件,并将它们挂载到主 FastAPI 应用的 `/plugins/<plugin_name>` 前缀下。 - 新增了全局配置 `[plugin_http_system]`,提供了总开关、API 速率限制和 API 密钥认证 (`X-API-Key`) 等功能,以确保端点的安全性和稳定性。 - 更新了 `hello_world_plugin` 插件,增加了一个简单的 `/greet` 端点作为实现示例。
This commit is contained in:
@@ -10,10 +10,12 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import orjson
|
||||
from fastapi import APIRouter, HTTPException, Query, Request
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Request
|
||||
from fastapi.responses import HTMLResponse, JSONResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
from src.common.security import get_api_key
|
||||
|
||||
# 调整项目根目录的计算方式
|
||||
project_root = Path(__file__).parent.parent.parent
|
||||
data_dir = project_root / "data" / "memory_graph"
|
||||
@@ -23,7 +25,7 @@ graph_data_cache = None
|
||||
current_data_file = None
|
||||
|
||||
# FastAPI 路由
|
||||
router = APIRouter()
|
||||
router = APIRouter(dependencies=[Depends(get_api_key)])
|
||||
|
||||
# Jinja2 模板引擎
|
||||
templates = Jinja2Templates(directory=str(Path(__file__).parent / "templates"))
|
||||
|
||||
Reference in New Issue
Block a user