|
| 1 | +"""Pipeline package exports. |
| 2 | +
|
| 3 | +This module intentionally avoids eager imports of all pipeline stage modules to |
| 4 | +prevent import-time cycles. Stage classes remain available via lazy attribute |
| 5 | +resolution for backward compatibility. |
| 6 | +""" |
| 7 | + |
| 8 | +from __future__ import annotations |
| 9 | + |
| 10 | +from importlib import import_module |
| 11 | +from typing import Any |
| 12 | + |
1 | 13 | from astrbot.core.message.message_event_result import ( |
2 | 14 | EventResultType, |
3 | 15 | MessageEventResult, |
4 | 16 | ) |
5 | 17 |
|
6 | | -from .content_safety_check.stage import ContentSafetyCheckStage |
7 | | -from .preprocess_stage.stage import PreProcessStage |
8 | | -from .process_stage.stage import ProcessStage |
9 | | -from .rate_limit_check.stage import RateLimitStage |
10 | | -from .respond.stage import RespondStage |
11 | | -from .result_decorate.stage import ResultDecorateStage |
12 | | -from .session_status_check.stage import SessionStatusCheckStage |
13 | | -from .waking_check.stage import WakingCheckStage |
14 | | -from .whitelist_check.stage import WhitelistCheckStage |
15 | | - |
16 | | -# 管道阶段顺序 |
17 | | -STAGES_ORDER = [ |
18 | | - "WakingCheckStage", # 检查是否需要唤醒 |
19 | | - "WhitelistCheckStage", # 检查是否在群聊/私聊白名单 |
20 | | - "SessionStatusCheckStage", # 检查会话是否整体启用 |
21 | | - "RateLimitStage", # 检查会话是否超过频率限制 |
22 | | - "ContentSafetyCheckStage", # 检查内容安全 |
23 | | - "PreProcessStage", # 预处理 |
24 | | - "ProcessStage", # 交由 Stars 处理(a.k.a 插件),或者 LLM 调用 |
25 | | - "ResultDecorateStage", # 处理结果,比如添加回复前缀、t2i、转换为语音 等 |
26 | | - "RespondStage", # 发送消息 |
27 | | -] |
| 18 | +from .stage_order import STAGES_ORDER |
| 19 | + |
| 20 | +_LAZY_EXPORTS = { |
| 21 | + "ContentSafetyCheckStage": ( |
| 22 | + "astrbot.core.pipeline.content_safety_check.stage", |
| 23 | + "ContentSafetyCheckStage", |
| 24 | + ), |
| 25 | + "PreProcessStage": ( |
| 26 | + "astrbot.core.pipeline.preprocess_stage.stage", |
| 27 | + "PreProcessStage", |
| 28 | + ), |
| 29 | + "ProcessStage": ( |
| 30 | + "astrbot.core.pipeline.process_stage.stage", |
| 31 | + "ProcessStage", |
| 32 | + ), |
| 33 | + "RateLimitStage": ( |
| 34 | + "astrbot.core.pipeline.rate_limit_check.stage", |
| 35 | + "RateLimitStage", |
| 36 | + ), |
| 37 | + "RespondStage": ( |
| 38 | + "astrbot.core.pipeline.respond.stage", |
| 39 | + "RespondStage", |
| 40 | + ), |
| 41 | + "ResultDecorateStage": ( |
| 42 | + "astrbot.core.pipeline.result_decorate.stage", |
| 43 | + "ResultDecorateStage", |
| 44 | + ), |
| 45 | + "SessionStatusCheckStage": ( |
| 46 | + "astrbot.core.pipeline.session_status_check.stage", |
| 47 | + "SessionStatusCheckStage", |
| 48 | + ), |
| 49 | + "WakingCheckStage": ( |
| 50 | + "astrbot.core.pipeline.waking_check.stage", |
| 51 | + "WakingCheckStage", |
| 52 | + ), |
| 53 | + "WhitelistCheckStage": ( |
| 54 | + "astrbot.core.pipeline.whitelist_check.stage", |
| 55 | + "WhitelistCheckStage", |
| 56 | + ), |
| 57 | +} |
28 | 58 |
|
29 | 59 | __all__ = [ |
30 | 60 | "ContentSafetyCheckStage", |
|
36 | 66 | "RespondStage", |
37 | 67 | "ResultDecorateStage", |
38 | 68 | "SessionStatusCheckStage", |
| 69 | + "STAGES_ORDER", |
39 | 70 | "WakingCheckStage", |
40 | 71 | "WhitelistCheckStage", |
41 | 72 | ] |
| 73 | + |
| 74 | + |
| 75 | +def __getattr__(name: str) -> Any: |
| 76 | + if name not in _LAZY_EXPORTS: |
| 77 | + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") |
| 78 | + module_path, attr_name = _LAZY_EXPORTS[name] |
| 79 | + module = import_module(module_path) |
| 80 | + value = getattr(module, attr_name) |
| 81 | + globals()[name] = value |
| 82 | + return value |
| 83 | + |
| 84 | + |
| 85 | +def __dir__() -> list[str]: |
| 86 | + return sorted(set(globals()) | set(__all__)) |
0 commit comments