mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-16 01:40:15 +08:00
`abort_signal` (asyncio.Event) is passed via **kwargs into payloads during tool_call streaming, causing "Object of type Event is not JSON serializable" when the OpenAI client tries to serialize the request body. Regression test added: test_prepare_chat_payload_strips_non_json_serializable_kwargs
2.5 KiB
2.5 KiB
1. PluginLoader Trait & Python 聚合层
架构边界:核心加载逻辑在 Rust FFI,Python 胶水层仅做类型转换和聚合
- 1.1 Define
PluginLoaderabstract base class inastrbot/_internal/protocols/abp/loader.py - 1.2 Define
PluginInstancedataclass (plugin_id, instance, metadata) - 1.3 Define
PluginRegistryclass inastrbot/_internal/protocols/abp/registry.py(Python 聚合层,调用 Rust FFI) - 1.4 Add
register()andunregister()methods to PluginRegistry - 1.5 Add
load_plugin()/unload_plugin()wrapper calling Rust FFI
2. Tool Discovery & Registry
架构边界:
tool_router.rs核心在 Rust,Python 层仅做聚合和转发
- 2.1 Create
astrbot/_internal/protocols/abp/tool_registry.py - 2.2 Implement
ToolDefdataclass (name, description, parameters schema) - 2.3 Implement
ToolRegistry.register(plugin_id, tools)with Schema validation (Python) - 2.4 Implement
ToolRegistry.list_tools()(aggregate all plugins via Rust FFIlist_tools()) - 2.5 Implement
ToolRegistry.call_tool(tool_name, args)(delegate to Rust FFIroute_tool_call()) - 2.6 Implement
tools/listJSON-RPC endpoint in plugin base class - 2.7 Add JSON Schema Draft-07 validation (jsonschema library)
3. FFI Bindings
⚠️ 禁止使用 ctypes:所有 FFI 必须通过 PyO3 绑定(rust-ffi.md 规范)
- 3.1 Audit existing
_core.pyifor missing ABP types - 3.2 Add
plugin_loader_*FFI function signatures to rust-ffi.md (if missing) - 3.3 Implement Python → Rust plugin loader calls via PyO3 binding
- 3.4 Add async wrapper using
run_in_executorfor PyO3 FFI calls - 3.5 Update
astrbot/_internal/protocols/abp/manager.pyto use FFI bindings
4. Configuration Integration
- 4.1 Define
pluginssection inconfig.yamlschema - 4.2 Implement
PluginConfigdataclass parsing - 4.3 Integrate PluginRegistry initialization into AstrBot startup
- 4.4 Add connection pooling for Unix Socket transport
- 4.5 Write integration test for config → plugin loading flow
5. Testing
- 5.1 Write unit tests for PluginLoader trait
- 5.2 Write unit tests for Python PluginRegistry (mock Rust FFI)
- 5.3 Write unit tests for ToolRegistry
- 5.4 Write integration tests for plugin loading (requires Rust FFI stub)
- 5.5 Write integration tests for tools/list + tools/call flow
- 5.6 Run
ruff check .andruff format . - 5.7 Run
uvx ty checkfor type validation