mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-19 02:12:46 +08:00
feat: 实现 v4 API 兼容层,支持旧版插件导入路径
新增模块: - api/basic/: AstrBotConfig, BaseConversationManager, Conversation - api/event/: AstrMessageEvent, AstrBotMessage, EventType, MessageType, MessageSession, EventResult 等核心事件类型 - api/message/: MessageChain 及所有消息组件 (Plain, At, Image, File 等) - api/platform/: PlatformMetadata 平台元数据类型 - api/provider/: LLMResponse 提供者响应实体 - api/star/star.py: StarMetadata 插件元数据类型 更新模块: - api/__init__.py: 导出所有子模块 - api/components/: 扩展 Command 兼容性 - api/event/filter.py: 增强 filter 装饰器兼容性 - context.py, decorators.py, events.py: 顶层兼容入口 测试更新: - test_api_event_filter.py: 验证 filter 兼容性 - test_api_modules.py: 验证新模块可导入 - test_handler_dispatcher.py: 验证处理器分发 文档更新: - AGENTS.md/CLAUDE.md: 添加兼容层设计说明,避免重复造轮子 设计原则: - 兼容层通过 thin re-export 方式暴露旧版 API - 不复制独立运行时逻辑,保持架构清晰 - 新版推荐使用顶层模块导入路径
This commit is contained in:
7
src-new/astrbot_sdk/api/basic/__init__.py
Normal file
7
src-new/astrbot_sdk/api/basic/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
"""旧版 ``astrbot_sdk.api.basic`` 的兼容入口。"""
|
||||
|
||||
from .astrbot_config import AstrBotConfig
|
||||
from .conversation_mgr import BaseConversationManager
|
||||
from .entities import Conversation
|
||||
|
||||
__all__ = ["AstrBotConfig", "BaseConversationManager", "Conversation"]
|
||||
8
src-new/astrbot_sdk/api/basic/astrbot_config.py
Normal file
8
src-new/astrbot_sdk/api/basic/astrbot_config.py
Normal file
@@ -0,0 +1,8 @@
|
||||
"""旧版配置对象兼容类型。"""
|
||||
|
||||
|
||||
class AstrBotConfig(dict):
|
||||
"""兼容旧版 ``AstrBotConfig``。
|
||||
|
||||
旧版实现本身就是 ``dict`` 的薄封装,兼容层保持这一行为。
|
||||
"""
|
||||
5
src-new/astrbot_sdk/api/basic/conversation_mgr.py
Normal file
5
src-new/astrbot_sdk/api/basic/conversation_mgr.py
Normal file
@@ -0,0 +1,5 @@
|
||||
"""旧版会话管理器兼容导出。"""
|
||||
|
||||
from ..._legacy_api import LegacyConversationManager as BaseConversationManager
|
||||
|
||||
__all__ = ["BaseConversationManager"]
|
||||
20
src-new/astrbot_sdk/api/basic/entities.py
Normal file
20
src-new/astrbot_sdk/api/basic/entities.py
Normal file
@@ -0,0 +1,20 @@
|
||||
"""旧版基础实体兼容类型。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class Conversation:
|
||||
"""兼容旧版对话实体。"""
|
||||
|
||||
platform_id: str
|
||||
user_id: str
|
||||
cid: str
|
||||
history: list[dict[str, Any]] = field(default_factory=list)
|
||||
title: str | None = ""
|
||||
persona_id: str | None = ""
|
||||
created_at: int = 0
|
||||
updated_at: int = 0
|
||||
Reference in New Issue
Block a user