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:
committed by
Windpicker-owo
parent
fea007b429
commit
717d4ba555
@@ -34,6 +34,7 @@ from src.config.official_configs import (
|
||||
PermissionConfig,
|
||||
PersonalityConfig,
|
||||
PlanningSystemConfig,
|
||||
PluginHttpSystemConfig,
|
||||
ProactiveThinkingConfig,
|
||||
ReactionConfig,
|
||||
ResponsePostProcessConfig,
|
||||
@@ -414,6 +415,9 @@ class Config(ValidatedConfigBase):
|
||||
proactive_thinking: ProactiveThinkingConfig = Field(
|
||||
default_factory=lambda: ProactiveThinkingConfig(), description="主动思考配置"
|
||||
)
|
||||
plugin_http_system: PluginHttpSystemConfig = Field(
|
||||
default_factory=lambda: PluginHttpSystemConfig(), description="插件HTTP端点系统配置"
|
||||
)
|
||||
|
||||
|
||||
class APIAdapterConfig(ValidatedConfigBase):
|
||||
|
||||
@@ -736,6 +736,23 @@ class CommandConfig(ValidatedConfigBase):
|
||||
command_prefixes: list[str] = Field(default_factory=lambda: ["/", "!", ".", "#"], description="支持的命令前缀列表")
|
||||
|
||||
|
||||
class PluginHttpSystemConfig(ValidatedConfigBase):
|
||||
"""插件http系统相关配置"""
|
||||
|
||||
enable_plugin_http_endpoints: bool = Field(
|
||||
default=True, description="总开关,是否允许插件创建HTTP端点"
|
||||
)
|
||||
plugin_api_rate_limit_enable: bool = Field(
|
||||
default=True, description="是否为插件API启用全局速率限制"
|
||||
)
|
||||
plugin_api_rate_limit_default: str = Field(
|
||||
default="100/minute", description="插件API的默认速率限制策略"
|
||||
)
|
||||
plugin_api_valid_keys: list[str] = Field(
|
||||
default_factory=list, description="有效的API密钥列表,用于插件认证"
|
||||
)
|
||||
|
||||
|
||||
class MasterPromptConfig(ValidatedConfigBase):
|
||||
"""主人身份提示词配置"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user