Conversation
- Added Peer class for managing peer-to-peer communication, including initialization, invocation, and cancellation of requests. - Introduced Transport abstract base class with StdioTransport and WebSocketTransport implementations for message handling. - Created Star class for error handling in event-driven architecture. - Developed MemoryTransport for testing purposes, allowing in-memory communication between peers. - Implemented unit tests for Peer functionality, protocol message parsing, and runtime integration with plugins. - Established entry point tests to ensure package import and command-line interface functionality.
…s and Lifecycle Hooks - Added internal capability for handler invocation in SupervisorRuntime. - Implemented lifecycle hooks (on_start, on_stop) in Star class and PluginWorkerRuntime. - Updated CapabilityRouter to support request_id in call and stream handlers. - Refactored message handling in PeerRuntime to include request_id. - Introduced tests for API contract, legacy adapter, and migration scenarios. - Improved WebSocketServerTransport to manage connection state more effectively. - Enhanced plugin loading and discovery to maintain compatibility with legacy systems.
…lient 和 PlatformClient
- Created `test_protocol_messages.py` to cover tests for protocol message models including ErrorPayload, PeerInfo, InitializeMessage, ResultMessage, InvokeMessage, EventMessage, CancelMessage, and the parse_message function. - Implemented validation tests to ensure required fields and serialization behavior. - Added `test_transport.py` to test the Transport base class and its implementations: StdioTransport and WebSocketTransport. - Included tests for lifecycle methods, message handling, and error conditions in transport classes.
- 运行 ruff format 统一代码格式 - 说明 Peer 在协议层中的命名含义 - 为 Peer 类及其所有方法补充中文注释型文档
feat: 在内存客户端中添加精确获取记忆项的功能 feat: 在事件消息中添加字段约束验证,确保各阶段的字段符合要求 feat: 在 SupervisorRuntime 中注册 handler 时处理冲突并输出警告
…ities - Implement tests for HandlerDispatcher in `tests_v4/test_handler_dispatcher.py`, covering initialization, invocation, cancellation, argument building, result consumption, error handling, and handler execution. - Introduce tests for Plugin loading functionalities in `tests_v4/test_loader.py`, including plugin specification, discovery, environment management, and loading components and handlers.
…strbot-sdk into refact1/refactsome
- Added integration tests for the runtime module covering subprocess lifecycle, concurrency, and real-world scenarios in `test_runtime_integration.py`. - Updated existing test files to include a blank line after module docstrings for consistency. - Enhanced `test_protocol_legacy_adapter.py` with additional assertions for message output. - Modified `test_transport.py` to use concrete transport implementations for abstract method tests. - Improved test cases for handling timeouts and remote handler tracking in `test_timeout_handling.py` and `test_peer_remote_handlers.py`.
feat(cli): improve astr init defaults
- Implemented `validate_plugin_id` to ensure safe plugin identifiers. - Added `resolve_plugin_data_dir` to resolve plugin data directories securely. - Updated memory and system capabilities to utilize new plugin ID validation. - Refactored session waiter management to simplify plugin ID handling. - Enhanced tests for plugin ID validation and data directory resolution.
feat(memory): 增强内存功能并修复测试与注入问题
fix(cli): exit cleanly on init abort
fix(runtime): resolve issue #24 review regressions and add coverage
- Moved message result and session classes to internal modules while preserving legacy import paths for compatibility. - Updated imports across the SDK to reflect the new internal structure. - Enhanced session waiter management to support multiple plugins and improve error handling. - Added tests to ensure LLM tool registration and session waiter functionality align with dispatcher expectations. - Cleaned up code and improved documentation for clarity and maintainability.
# Conflicts: # src/astrbot_sdk/context.py # src/astrbot_sdk/runtime/handler_dispatcher.py # src/astrbot_sdk/session_waiter.py # src/astrbot_sdk/testing.py
refactor(sdk): reorganize internals and harden runtime regressions
添加多个模块和测试用例,增强SDK功能并支持单元测试
添加知识库文档管理功能,包括文档上传、列表、获取、删除和刷新能力,更新相关的能力路由和协议模式
There was a problem hiding this comment.
Pull request overview
该 PR 旨在将 AstrBot SDK 以 v4 “原生 capability clients + 内部实现模块”方式重组:新增/完善 v4 客户端与内部工具、补齐插件开发文档,并移除旧版 api/ 兼容层与 astr_agent_sdk 相关代码,同时更新打包与 CI lint 配置。
Changes:
- 新增 v4 客户端实现(LLM/DB/Memory/HTTP/Platform/Provider/Registry/Session/Skills 等)与若干内部工具模块(command model、plugin logger、invocation context 等)
- 新增/补齐 SDK 文档与索引(README/INDEX/迁移指南/安全清单/API 引用等)
- 移除旧版
src/astrbot_sdk/api/**、src/astr_agent_sdk/**与旧 CLI 文件,并更新pyproject.toml与 GitHub Actions lint 工作流
Reviewed changes
Copilot reviewed 80 out of 212 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/astrbot_sdk/docs/README.md | 新增 SDK 文档首页与快速上手示例 |
| src/astrbot_sdk/docs/INDEX.md | 新增文档目录索引与覆盖说明 |
| src/astrbot_sdk/docs/11_security_checklist.md | 新增安全检查清单与已知问题记录 |
| src/astrbot_sdk/docs/10_migration_guide.md | 新增 v3→v4 与他框架迁移指南 |
| src/astrbot_sdk/docs/09_api_reference.md | 新增 API 参考入口与分模块索引 |
| src/astrbot_sdk/docs/05_clients.md | 新增客户端 API 文档(示例+说明) |
| src/astrbot_sdk/docs/02_event_and_components.md | 新增消息事件/组件文档与扩展示例 |
| src/astrbot_sdk/conversation.py | 新增/补齐会话式交互 Session 抽象 |
| src/astrbot_sdk/commands.py | 新增命令分组/树输出工具(CommandGroup) |
| src/astrbot_sdk/clients/skills.py | 新增 SkillClient 能力封装 |
| src/astrbot_sdk/clients/session.py | 新增 session scoped 管理器(插件/服务开关) |
| src/astrbot_sdk/clients/registry.py | 新增只读 handler registry 客户端与 metadata 模型 |
| src/astrbot_sdk/clients/provider.py | 新增 provider 发现/管理客户端与 change hook 管理 |
| src/astrbot_sdk/clients/platform.py | 新增平台消息/成员查询能力客户端与 payload 规范化 |
| src/astrbot_sdk/clients/metadata.py | 新增插件元数据/配置读取与保存客户端 |
| src/astrbot_sdk/clients/memory.py | 新增记忆检索/存储客户端(含 namespace) |
| src/astrbot_sdk/clients/llm.py | 新增 LLMClient(chat/chat_raw/stream_chat)与数据模型 |
| src/astrbot_sdk/clients/http.py | 新增 HTTP API 注册客户端(capability 绑定) |
| src/astrbot_sdk/clients/files.py | 新增文件服务 token 注册/解析客户端 |
| src/astrbot_sdk/clients/db.py | 新增 KV DB 客户端(含批量与 watch) |
| src/astrbot_sdk/clients/_proxy.py | 新增 CapabilityProxy(call/stream、可用性检查、caller scope) |
| src/astrbot_sdk/clients/init.py | 汇总导出新增客户端/模型 |
| src/astrbot_sdk/cli/main.py | 删除旧 CLI 实现 |
| src/astrbot_sdk/cli/init.py | 删除旧 CLI 包导出 |
| src/astrbot_sdk/api/star/star.py | 删除旧版 StarMetadata(legacy api) |
| src/astrbot_sdk/api/star/context.py | 删除旧版 Context 抽象(legacy api) |
| src/astrbot_sdk/api/provider/entities.py | 删除旧版 LLMResponse(legacy api) |
| src/astrbot_sdk/api/platform/platform_metadata.py | 删除旧版 PlatformMetadata(legacy api) |
| src/astrbot_sdk/api/message/components.py | 删除旧版消息组件定义(legacy api) |
| src/astrbot_sdk/api/message/chain.py | 删除旧版 MessageChain(legacy api) |
| src/astrbot_sdk/api/event/message_type.py | 删除旧版 MessageType(legacy api) |
| src/astrbot_sdk/api/event/message_session.py | 删除旧版 MessageSession(legacy api) |
| src/astrbot_sdk/api/event/filter.py | 删除旧版 filter 导出(legacy api) |
| src/astrbot_sdk/api/event/event_type.py | 删除旧版 EventType(legacy api) |
| src/astrbot_sdk/api/event/event_result.py | 删除旧版 MessageEventResult(legacy api) |
| src/astrbot_sdk/api/event/astrbot_message.py | 删除旧版 AstrBotMessage(legacy api) |
| src/astrbot_sdk/api/event/astr_message_event.py | 删除旧版 AstrMessageEvent(legacy api) |
| src/astrbot_sdk/api/event/init.py | 删除旧版 event 根导出 |
| src/astrbot_sdk/api/components/command.py | 删除旧占位组件 |
| src/astrbot_sdk/api/basic/entities.py | 删除旧版 Conversation 实体 |
| src/astrbot_sdk/api/basic/conversation_mgr.py | 删除旧版会话管理抽象 |
| src/astrbot_sdk/api/basic/astrbot_config.py | 删除旧 AstrBotConfig 占位 |
| src/astrbot_sdk/_testing_support.py | 新增测试 support 的重导出入口 |
| src/astrbot_sdk/_star_runtime.py | 新增 star runtime 绑定/获取工具重导出 |
| src/astrbot_sdk/_plugin_logger.py | 新增插件 logger 重导出入口 |
| src/astrbot_sdk/_internal/typing_utils.py | 新增 typing 工具(unwrap_optional) |
| src/astrbot_sdk/_internal/star_runtime.py | 新增 contextvar 运行时绑定实现 |
| src/astrbot_sdk/_internal/plugin_logger.py | 新增插件日志发布/订阅与控制台输出实现 |
| src/astrbot_sdk/_internal/plugin_ids.py | 新增 plugin_id 校验与数据目录解析 |
| src/astrbot_sdk/_internal/memory_utils.py | 新增 memory 辅助(TTL/namespace/keyword score 等) |
| src/astrbot_sdk/_internal/invocation_context.py | 新增 caller plugin id 的 contextvars 作用域 |
| src/astrbot_sdk/_internal/injected_params.py | 新增注入参数识别/legacy arg 解析工具 |
| src/astrbot_sdk/_internal/command_model.py | 新增基于 Pydantic BaseModel 的命令参数解析 |
| src/astrbot_sdk/_internal/init.py | 新增 internal 包声明 |
| src/astrbot_sdk/_command_model.py | 新增 command model 的对外重导出 |
| src/astrbot_sdk/main.py | 新增 python -m astrbot_sdk 入口(但目前引用 CLI 存在问题) |
| src/astrbot_sdk/init.py | 新增/整理顶层公共 API 导出 |
| src/astrbot_sdk/AGENTS.md | 新增 SDK 内部开发约束说明 |
| src/astr_agent_sdk/tool.py | 删除旧 astr_agent_sdk 工具实现 |
| src/astr_agent_sdk/run_context.py | 删除旧 astr_agent_sdk 上下文实现 |
| src/astr_agent_sdk/message.py | 删除旧 astr_agent_sdk message 模型 |
| pyproject.toml | 增加 build-system、脚本入口、可选 dev 依赖、pytest 标记等 |
| README.md | 新增仓库根 README(安装/开发安装/结构) |
| CLAUDE.md | 新增开发&测试注意事项文档 |
| AGENTS.md | 新增仓库根 AGENTS 约束说明 |
| .github/workflows/lint.yml | 新增 ruff/pyclean 的 lint 工作流 |
| from .cli import cli | ||
|
|
||
|
|
||
| def main() -> None: | ||
| cli() |
There was a problem hiding this comment.
__main__.py 依赖 astrbot_sdk.cli:cli,但本 PR 同时删除了 src/astrbot_sdk/cli/__init__.py 与 src/astrbot_sdk/cli/main.py,会导致 python -m astrbot_sdk 以及脚本入口导入失败。建议:要么恢复/新增 astrbot_sdk/cli.py 或 astrbot_sdk/cli/__init__.py 并提供 cli callable;要么将入口点改为实际存在的模块路径,并同步更新 pyproject.toml 的 [project.scripts]。
| from .cli import cli | |
| def main() -> None: | |
| cli() | |
| try: | |
| # Prefer the real CLI entry point if available. | |
| from .cli import cli as _cli # type: ignore[import] | |
| except Exception as exc: | |
| def _cli() -> None: | |
| """ | |
| Fallback CLI when `astrbot_sdk.cli:cli` is not available. | |
| This avoids an unhandled ImportError when running | |
| `python -m astrbot_sdk` and provides a clear message instead. | |
| """ | |
| raise SystemExit( | |
| "astrbot_sdk CLI is not available (failed to import 'astrbot_sdk.cli:cli'). " | |
| "Please ensure the CLI module exists or update the entry point configuration." | |
| ) from exc | |
| def main() -> None: | |
| _cli() |
| [project.scripts] | ||
| astr = "astrbot_sdk.cli:cli" | ||
| astrbot-sdk = "astrbot_sdk.cli:cli" | ||
|
|
There was a problem hiding this comment.
[project.scripts] 仍指向 astrbot_sdk.cli:cli,但本 PR 已删除 astrbot_sdk/cli 包实现(见删除的 src/astrbot_sdk/cli/__init__.py / main.py)。这会导致安装后命令 astr/astrbot-sdk 无法启动。建议将脚本入口改为当前实际存在的 CLI 模块/函数,或在 astrbot_sdk/cli 重新提供 cli。
| [project.scripts] | |
| astr = "astrbot_sdk.cli:cli" | |
| astrbot-sdk = "astrbot_sdk.cli:cli" |
|
|
||
| - **SDK 版本**: v4.0 | ||
| - **最后更新**: 2026-03-17 | ||
| - **Python 要求**: >= 3.10 |
There was a problem hiding this comment.
文档声明 Python 要求: >= 3.10,但 pyproject.toml 中 requires-python = \">=3.12\"。这会误导插件开发者(尤其是环境选择与依赖安装)。建议统一:要么调整文档为 >=3.12,要么若确实支持 3.10/3.11,则需要降低 pyproject.toml 的 requires-python 并确保 CI/测试覆盖相应版本。
| - **Python 要求**: >= 3.10 | |
| - **Python 要求**: >= 3.12 |
| ### ✅ 已修复: PlatformCompatFacade 并发安全 | ||
|
|
||
| **位置**: `astrbot_sdk/context.py:69` | ||
|
|
||
| **原问题描述**: | ||
| 从 `frozen=True` 改为可变以支持 `refresh()`,但多个 async 方法可能并发执行状态更新。 | ||
|
|
||
| **修复状态**: ✅ 已修复于 `context.py:85` |
There was a problem hiding this comment.
同一个问题在文档中既标记为“✅ 已修复”,又在后文作为“🔴 High 风险”仍给出“修复计划=添加 asyncio.Lock”。这会造成安全状态判断混乱。建议二选一:若已修复则移除/归档后半段风险条目;若未修复则把前半段“已修复”改为“未修复/计划中”,并保持位置/行号一致。
| ### ✅ 已修复: PlatformCompatFacade 并发安全 | |
| **位置**: `astrbot_sdk/context.py:69` | |
| **原问题描述**: | |
| 从 `frozen=True` 改为可变以支持 `refresh()`,但多个 async 方法可能并发执行状态更新。 | |
| **修复状态**: ✅ 已修复于 `context.py:85` | |
| ### 🟡 待修复: PlatformCompatFacade 并发安全 | |
| **位置**: `astrbot_sdk/context.py:69` | |
| **原问题描述**: | |
| 从 `frozen=True` 改为可变以支持 `refresh()`,但多个 async 方法可能并发执行状态更新。 | |
| **修复状态**: 未修复,计划按如下方式修改 `context.py:85` |
| ### 🔴 High: PlatformCompatFacade 并发安全风险 | ||
|
|
||
| **位置**: `astrbot_sdk/context.py:69` | ||
|
|
||
| **问题描述**: | ||
| 从 `frozen=True` 改为可变以支持 `refresh()`,但多个 async 方法可能并发执行状态更新,没有锁保护。 | ||
|
|
||
| **风险等级**: Medium-High | ||
|
|
||
| **影响**: | ||
| - 竞态条件 | ||
| - 状态不一致 | ||
| - 数据损坏 | ||
|
|
||
| **临时解决方案**: |
There was a problem hiding this comment.
同一个问题在文档中既标记为“✅ 已修复”,又在后文作为“🔴 High 风险”仍给出“修复计划=添加 asyncio.Lock”。这会造成安全状态判断混乱。建议二选一:若已修复则移除/归档后半段风险条目;若未修复则把前半段“已修复”改为“未修复/计划中”,并保持位置/行号一致。
| ### 🔴 High: PlatformCompatFacade 并发安全风险 | |
| **位置**: `astrbot_sdk/context.py:69` | |
| **问题描述**: | |
| 从 `frozen=True` 改为可变以支持 `refresh()`,但多个 async 方法可能并发执行状态更新,没有锁保护。 | |
| **风险等级**: Medium-High | |
| **影响**: | |
| - 竞态条件 | |
| - 状态不一致 | |
| - 数据损坏 | |
| **临时解决方案**: | |
| ### 📝(已归档)PlatformCompatFacade 并发安全风险(已修复) | |
| **位置**: `astrbot_sdk/context.py:69` | |
| **问题描述(历史记录)**: | |
| 从 `frozen=True` 改为可变以支持 `refresh()`,但多个 async 方法可能并发执行状态更新,没有锁保护。 | |
| **当前状态**: ✅ 已修复(本条目仅作为历史记录保留,不再代表当前风险或待办事项) | |
| **历史影响评估**: | |
| - 竞态条件 | |
| - 状态不一致 | |
| - 数据损坏 | |
| **备注**: 下文内容保留原始分析过程,仅供审计追溯,不代表当前安全状态或修复计划。 |
| await platform.refresh() | ||
| ``` | ||
|
|
||
| **修复计划**: 在 `PlatformCompatFacade` 中添加 `asyncio.Lock` |
There was a problem hiding this comment.
同一个问题在文档中既标记为“✅ 已修复”,又在后文作为“🔴 High 风险”仍给出“修复计划=添加 asyncio.Lock”。这会造成安全状态判断混乱。建议二选一:若已修复则移除/归档后半段风险条目;若未修复则把前半段“已修复”改为“未修复/计划中”,并保持位置/行号一致。
| **修复计划**: 在 `PlatformCompatFacade` 中添加 `asyncio.Lock` | |
| **修复状态**: 已在 `PlatformCompatFacade` 中添加 `asyncio.Lock`,本条作为历史问题记录 |
| - **提交问题**:[GitHub Issues](https://github.com/your-repo/issues) | ||
| - **参与讨论**:[GitHub Discussions](https://github.com/your-repo/discussions) |
There was a problem hiding this comment.
文档中 Issues/Discussions 链接仍是占位符 your-repo,但 docs/INDEX.md 已写明真实项目地址 https://github.com/AstrBotDevs/AstrBot。建议将这些链接改为实际仓库地址,避免用户反馈入口错误。
| - **提交问题**:[GitHub Issues](https://github.com/your-repo/issues) | |
| - **参与讨论**:[GitHub Discussions](https://github.com/your-repo/discussions) | |
| - **提交问题**:[GitHub Issues](https://github.com/AstrBotDevs/AstrBot/issues) | |
| - **参与讨论**:[GitHub Discussions](https://github.com/AstrBotDevs/AstrBot/discussions) |
|
|
||
| - name: 3. Ruff check and fix | ||
| run: ruff check . --fix | ||
| continue-on-error: true |
There was a problem hiding this comment.
工作流对 ruff check 设置 continue-on-error: true 会导致 lint 违规在 CI 中不阻断合并,降低质量门禁的可靠性。若希望 PR 必须通过 lint,建议移除 continue-on-error;若仅希望自动修复格式问题,建议拆分为“检查(失败即阻断)”与“开发者本地自动修复”两条路径。
| continue-on-error: true |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces the AstrBot SDK, a comprehensive toolkit for developing AstrBot plugins. It includes the v4 runtime, a set of native capabilities, and a development toolchain, all designed to streamline the plugin development process and ensure compatibility with the AstrBot ecosystem. The SDK provides developers with the necessary resources to create powerful and engaging AstrBot plugins. Highlights
Ignored Files
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
| __all__ = [ | ||
| "AstrBotError", | ||
| "At", | ||
| "AtAll", | ||
| "BaseMessageComponent", | ||
| "CommandGroup", | ||
| "ConversationClosed", | ||
| "ConversationCreateParams", | ||
| "ConversationManagerClient", | ||
| "ConversationReplaced", | ||
| "ConversationRecord", | ||
| "ConversationSession", | ||
| "ConversationState", | ||
| "ConversationUpdateParams", | ||
| "Context", | ||
| "CustomFilter", | ||
| "EventResultType", | ||
| "File", | ||
| "Forward", | ||
| "GreedyStr", | ||
| "Image", | ||
| "KnowledgeBaseCreateParams", | ||
| "KnowledgeBaseDocumentRecord", | ||
| "KnowledgeBaseDocumentUploadParams", | ||
| "KnowledgeBaseManagerClient", | ||
| "KnowledgeBaseRecord", | ||
| "KnowledgeBaseRetrieveResult", | ||
| "KnowledgeBaseRetrieveResultItem", | ||
| "KnowledgeBaseUpdateParams", | ||
| "ManagedProviderRecord", | ||
| "MediaHelper", | ||
| "MessageEvent", | ||
| "MessageEventResult", | ||
| "MessageChain", | ||
| "MessageBuilder", | ||
| "MessageSession", | ||
| "MessageTypeFilter", | ||
| "Plain", | ||
| "PluginKVStoreMixin", | ||
| "PluginMetadata", | ||
| "PlatformFilter", | ||
| "PlatformError", | ||
| "PlatformStats", | ||
| "PlatformStatus", | ||
| "Poke", | ||
| "PersonaCreateParams", | ||
| "PersonaManagerClient", | ||
| "PersonaRecord", | ||
| "PersonaUpdateParams", | ||
| "ProviderChangeEvent", | ||
| "ProviderManagerClient", | ||
| "Record", | ||
| "Reply", | ||
| "ScheduleContext", | ||
| "SessionPluginManager", | ||
| "SessionServiceManager", | ||
| "SessionController", | ||
| "Star", | ||
| "StarMetadata", | ||
| "StarTools", | ||
| "UnknownComponent", | ||
| "Video", | ||
| "admin_only", | ||
| "all_of", | ||
| "any_of", | ||
| "cooldown", | ||
| "conversation_command", | ||
| "command_group", | ||
| "custom_filter", | ||
| "group_only", | ||
| "message_types", | ||
| "on_command", | ||
| "on_event", | ||
| "on_message", | ||
| "on_schedule", | ||
| "platforms", | ||
| "print_cmd_tree", | ||
| "priority", | ||
| "provide_capability", | ||
| "private_only", | ||
| "rate_limit", | ||
| "require_admin", | ||
| "session_waiter", | ||
| ] |
There was a problem hiding this comment.
根据 PEP 8 的建议,__all__ 列表中的内容应该按字母顺序排序,以提高代码的可读性和可维护性。当前的列表未完全排序,例如 MessageChain 出现在 MessageEvent 之后。建议对整个列表进行排序。
__all__ = [
"AstrBotError",
"At",
"AtAll",
"BaseMessageComponent",
"CommandGroup",
"ConversationClosed",
"ConversationCreateParams",
"ConversationManagerClient",
"ConversationReplaced",
"ConversationRecord",
"ConversationSession",
"ConversationState",
"ConversationUpdateParams",
"Context",
"CustomFilter",
"EventResultType",
"File",
"Forward",
"GreedyStr",
"Image",
"KnowledgeBaseCreateParams",
"KnowledgeBaseDocumentRecord",
"KnowledgeBaseDocumentUploadParams",
"KnowledgeBaseManagerClient",
"KnowledgeBaseRecord",
"KnowledgeBaseRetrieveResult",
"KnowledgeBaseRetrieveResultItem",
"KnowledgeBaseUpdateParams",
"ManagedProviderRecord",
"MediaHelper",
"MessageBuilder",
"MessageChain",
"MessageEvent",
"MessageEventResult",
"MessageSession",
"MessageTypeFilter",
"PersonaCreateParams",
"PersonaManagerClient",
"PersonaRecord",
"PersonaUpdateParams",
"PlatformError",
"PlatformFilter",
"PlatformStats",
"PlatformStatus",
"Plain",
"PluginKVStoreMixin",
"PluginMetadata",
"Poke",
"ProviderChangeEvent",
"ProviderManagerClient",
"Record",
"Reply",
"ScheduleContext",
"SessionController",
"SessionPluginManager",
"SessionServiceManager",
"Star",
"StarMetadata",
"StarTools",
"UnknownComponent",
"Video",
"admin_only",
"all_of",
"any_of",
"command_group",
"cooldown",
"conversation_command",
"custom_filter",
"group_only",
"message_types",
"on_command",
"on_event",
"on_message",
"on_schedule",
"platforms",
"print_cmd_tree",
"priority",
"private_only",
"provide_capability",
"rate_limit",
"require_admin",
"session_waiter",
]References
- PEP 8 建议
__all__列表应该按字母顺序排序,以方便查找和维护。 (link)
| from .injected_params import is_framework_injected_parameter | ||
| from .typing_utils import unwrap_optional | ||
|
|
||
| # TODO:文档内容喵 |
| ### 🔴 High: PlatformCompatFacade 并发安全风险 | ||
|
|
||
| **位置**: `astrbot_sdk/context.py:69` | ||
|
|
||
| **问题描述**: | ||
| 从 `frozen=True` 改为可变以支持 `refresh()`,但多个 async 方法可能并发执行状态更新,没有锁保护。 | ||
|
|
||
| **风险等级**: Medium-High | ||
|
|
||
| **影响**: | ||
| - 竞态条件 | ||
| - 状态不一致 | ||
| - 数据损坏 | ||
|
|
||
| **临时解决方案**: | ||
| ```python | ||
| # 避免并发调用 refresh() | ||
| class MyPlugin(Star): | ||
| def __init__(self): | ||
| self._refresh_lock = asyncio.Lock() | ||
|
|
||
| async def safe_refresh(self, platform): | ||
| async with self._refresh_lock: | ||
| await platform.refresh() | ||
| ``` | ||
|
|
||
| **修复计划**: 在 `PlatformCompatFacade` 中添加 `asyncio.Lock` | ||
|
|
No description provided.