AstrBot 4.5.0__py3-none-any.whl → 4.5.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. astrbot/api/__init__.py +10 -11
  2. astrbot/api/event/__init__.py +5 -6
  3. astrbot/api/event/filter/__init__.py +37 -36
  4. astrbot/api/platform/__init__.py +7 -8
  5. astrbot/api/provider/__init__.py +7 -7
  6. astrbot/api/star/__init__.py +3 -4
  7. astrbot/api/util/__init__.py +2 -2
  8. astrbot/cli/__main__.py +5 -5
  9. astrbot/cli/commands/__init__.py +3 -3
  10. astrbot/cli/commands/cmd_conf.py +19 -16
  11. astrbot/cli/commands/cmd_init.py +3 -2
  12. astrbot/cli/commands/cmd_plug.py +8 -10
  13. astrbot/cli/commands/cmd_run.py +5 -6
  14. astrbot/cli/utils/__init__.py +6 -6
  15. astrbot/cli/utils/basic.py +14 -14
  16. astrbot/cli/utils/plugin.py +24 -15
  17. astrbot/cli/utils/version_comparator.py +10 -12
  18. astrbot/core/__init__.py +8 -6
  19. astrbot/core/agent/agent.py +3 -2
  20. astrbot/core/agent/handoff.py +6 -2
  21. astrbot/core/agent/hooks.py +9 -6
  22. astrbot/core/agent/mcp_client.py +50 -15
  23. astrbot/core/agent/message.py +168 -0
  24. astrbot/core/agent/response.py +2 -1
  25. astrbot/core/agent/run_context.py +2 -3
  26. astrbot/core/agent/runners/base.py +10 -13
  27. astrbot/core/agent/runners/tool_loop_agent_runner.py +52 -51
  28. astrbot/core/agent/tool.py +60 -41
  29. astrbot/core/agent/tool_executor.py +9 -3
  30. astrbot/core/astr_agent_context.py +3 -1
  31. astrbot/core/astrbot_config_mgr.py +29 -9
  32. astrbot/core/config/__init__.py +2 -2
  33. astrbot/core/config/astrbot_config.py +28 -26
  34. astrbot/core/config/default.py +44 -6
  35. astrbot/core/conversation_mgr.py +105 -36
  36. astrbot/core/core_lifecycle.py +68 -54
  37. astrbot/core/db/__init__.py +33 -18
  38. astrbot/core/db/migration/helper.py +18 -13
  39. astrbot/core/db/migration/migra_3_to_4.py +53 -34
  40. astrbot/core/db/migration/migra_45_to_46.py +1 -1
  41. astrbot/core/db/migration/shared_preferences_v3.py +2 -1
  42. astrbot/core/db/migration/sqlite_v3.py +26 -23
  43. astrbot/core/db/po.py +27 -18
  44. astrbot/core/db/sqlite.py +74 -45
  45. astrbot/core/db/vec_db/base.py +10 -14
  46. astrbot/core/db/vec_db/faiss_impl/document_storage.py +90 -77
  47. astrbot/core/db/vec_db/faiss_impl/embedding_storage.py +9 -3
  48. astrbot/core/db/vec_db/faiss_impl/vec_db.py +36 -31
  49. astrbot/core/event_bus.py +8 -6
  50. astrbot/core/file_token_service.py +6 -5
  51. astrbot/core/initial_loader.py +7 -5
  52. astrbot/core/knowledge_base/chunking/__init__.py +1 -3
  53. astrbot/core/knowledge_base/chunking/base.py +1 -0
  54. astrbot/core/knowledge_base/chunking/fixed_size.py +2 -0
  55. astrbot/core/knowledge_base/chunking/recursive.py +16 -10
  56. astrbot/core/knowledge_base/kb_db_sqlite.py +50 -48
  57. astrbot/core/knowledge_base/kb_helper.py +30 -17
  58. astrbot/core/knowledge_base/kb_mgr.py +6 -7
  59. astrbot/core/knowledge_base/models.py +10 -4
  60. astrbot/core/knowledge_base/parsers/__init__.py +3 -5
  61. astrbot/core/knowledge_base/parsers/base.py +1 -0
  62. astrbot/core/knowledge_base/parsers/markitdown_parser.py +2 -1
  63. astrbot/core/knowledge_base/parsers/pdf_parser.py +2 -1
  64. astrbot/core/knowledge_base/parsers/text_parser.py +1 -0
  65. astrbot/core/knowledge_base/parsers/util.py +1 -1
  66. astrbot/core/knowledge_base/retrieval/__init__.py +6 -8
  67. astrbot/core/knowledge_base/retrieval/manager.py +17 -14
  68. astrbot/core/knowledge_base/retrieval/rank_fusion.py +7 -3
  69. astrbot/core/knowledge_base/retrieval/sparse_retriever.py +11 -5
  70. astrbot/core/log.py +21 -13
  71. astrbot/core/message/components.py +123 -217
  72. astrbot/core/message/message_event_result.py +24 -24
  73. astrbot/core/persona_mgr.py +20 -11
  74. astrbot/core/pipeline/__init__.py +7 -7
  75. astrbot/core/pipeline/content_safety_check/stage.py +13 -9
  76. astrbot/core/pipeline/content_safety_check/strategies/__init__.py +1 -2
  77. astrbot/core/pipeline/content_safety_check/strategies/baidu_aip.py +12 -13
  78. astrbot/core/pipeline/content_safety_check/strategies/keywords.py +1 -0
  79. astrbot/core/pipeline/content_safety_check/strategies/strategy.py +6 -6
  80. astrbot/core/pipeline/context.py +4 -1
  81. astrbot/core/pipeline/context_utils.py +77 -7
  82. astrbot/core/pipeline/preprocess_stage/stage.py +12 -9
  83. astrbot/core/pipeline/process_stage/method/llm_request.py +125 -72
  84. astrbot/core/pipeline/process_stage/method/star_request.py +19 -17
  85. astrbot/core/pipeline/process_stage/stage.py +13 -10
  86. astrbot/core/pipeline/process_stage/utils.py +6 -5
  87. astrbot/core/pipeline/rate_limit_check/stage.py +37 -36
  88. astrbot/core/pipeline/respond/stage.py +23 -20
  89. astrbot/core/pipeline/result_decorate/stage.py +31 -23
  90. astrbot/core/pipeline/scheduler.py +12 -8
  91. astrbot/core/pipeline/session_status_check/stage.py +12 -8
  92. astrbot/core/pipeline/stage.py +10 -4
  93. astrbot/core/pipeline/waking_check/stage.py +24 -18
  94. astrbot/core/pipeline/whitelist_check/stage.py +10 -7
  95. astrbot/core/platform/__init__.py +6 -6
  96. astrbot/core/platform/astr_message_event.py +76 -110
  97. astrbot/core/platform/astrbot_message.py +11 -13
  98. astrbot/core/platform/manager.py +16 -15
  99. astrbot/core/platform/message_session.py +5 -3
  100. astrbot/core/platform/platform.py +16 -24
  101. astrbot/core/platform/platform_metadata.py +4 -4
  102. astrbot/core/platform/register.py +8 -8
  103. astrbot/core/platform/sources/aiocqhttp/aiocqhttp_message_event.py +23 -15
  104. astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +51 -33
  105. astrbot/core/platform/sources/dingtalk/dingtalk_adapter.py +47 -29
  106. astrbot/core/platform/sources/dingtalk/dingtalk_event.py +7 -3
  107. astrbot/core/platform/sources/discord/client.py +9 -6
  108. astrbot/core/platform/sources/discord/components.py +18 -14
  109. astrbot/core/platform/sources/discord/discord_platform_adapter.py +45 -30
  110. astrbot/core/platform/sources/discord/discord_platform_event.py +38 -30
  111. astrbot/core/platform/sources/lark/lark_adapter.py +23 -17
  112. astrbot/core/platform/sources/lark/lark_event.py +21 -14
  113. astrbot/core/platform/sources/misskey/misskey_adapter.py +107 -67
  114. astrbot/core/platform/sources/misskey/misskey_api.py +153 -129
  115. astrbot/core/platform/sources/misskey/misskey_event.py +20 -15
  116. astrbot/core/platform/sources/misskey/misskey_utils.py +74 -62
  117. astrbot/core/platform/sources/qqofficial/qqofficial_message_event.py +63 -44
  118. astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py +41 -26
  119. astrbot/core/platform/sources/qqofficial_webhook/qo_webhook_adapter.py +36 -17
  120. astrbot/core/platform/sources/qqofficial_webhook/qo_webhook_event.py +3 -1
  121. astrbot/core/platform/sources/qqofficial_webhook/qo_webhook_server.py +12 -7
  122. astrbot/core/platform/sources/satori/satori_adapter.py +56 -38
  123. astrbot/core/platform/sources/satori/satori_event.py +34 -25
  124. astrbot/core/platform/sources/slack/client.py +11 -9
  125. astrbot/core/platform/sources/slack/slack_adapter.py +52 -36
  126. astrbot/core/platform/sources/slack/slack_event.py +34 -24
  127. astrbot/core/platform/sources/telegram/tg_adapter.py +38 -18
  128. astrbot/core/platform/sources/telegram/tg_event.py +32 -18
  129. astrbot/core/platform/sources/webchat/webchat_adapter.py +27 -17
  130. astrbot/core/platform/sources/webchat/webchat_event.py +14 -10
  131. astrbot/core/platform/sources/wechatpadpro/wechatpadpro_adapter.py +115 -120
  132. astrbot/core/platform/sources/wechatpadpro/wechatpadpro_message_event.py +9 -8
  133. astrbot/core/platform/sources/wechatpadpro/xml_data_parser.py +15 -16
  134. astrbot/core/platform/sources/wecom/wecom_adapter.py +35 -18
  135. astrbot/core/platform/sources/wecom/wecom_event.py +55 -48
  136. astrbot/core/platform/sources/wecom/wecom_kf.py +34 -44
  137. astrbot/core/platform/sources/wecom/wecom_kf_message.py +26 -10
  138. astrbot/core/platform/sources/wecom_ai_bot/WXBizJsonMsgCrypt.py +18 -10
  139. astrbot/core/platform/sources/wecom_ai_bot/__init__.py +3 -5
  140. astrbot/core/platform/sources/wecom_ai_bot/ierror.py +0 -1
  141. astrbot/core/platform/sources/wecom_ai_bot/wecomai_adapter.py +61 -37
  142. astrbot/core/platform/sources/wecom_ai_bot/wecomai_api.py +67 -28
  143. astrbot/core/platform/sources/wecom_ai_bot/wecomai_event.py +8 -9
  144. astrbot/core/platform/sources/wecom_ai_bot/wecomai_queue_mgr.py +18 -9
  145. astrbot/core/platform/sources/wecom_ai_bot/wecomai_server.py +14 -12
  146. astrbot/core/platform/sources/wecom_ai_bot/wecomai_utils.py +22 -12
  147. astrbot/core/platform/sources/weixin_official_account/weixin_offacc_adapter.py +40 -26
  148. astrbot/core/platform/sources/weixin_official_account/weixin_offacc_event.py +47 -45
  149. astrbot/core/platform_message_history_mgr.py +5 -3
  150. astrbot/core/provider/__init__.py +2 -3
  151. astrbot/core/provider/entites.py +8 -8
  152. astrbot/core/provider/entities.py +61 -75
  153. astrbot/core/provider/func_tool_manager.py +59 -55
  154. astrbot/core/provider/manager.py +40 -22
  155. astrbot/core/provider/provider.py +72 -46
  156. astrbot/core/provider/register.py +7 -7
  157. astrbot/core/provider/sources/anthropic_source.py +48 -30
  158. astrbot/core/provider/sources/azure_tts_source.py +17 -13
  159. astrbot/core/provider/sources/coze_api_client.py +27 -17
  160. astrbot/core/provider/sources/coze_source.py +104 -87
  161. astrbot/core/provider/sources/dashscope_source.py +18 -11
  162. astrbot/core/provider/sources/dashscope_tts.py +36 -23
  163. astrbot/core/provider/sources/dify_source.py +25 -20
  164. astrbot/core/provider/sources/edge_tts_source.py +21 -17
  165. astrbot/core/provider/sources/fishaudio_tts_api_source.py +22 -14
  166. astrbot/core/provider/sources/gemini_embedding_source.py +12 -13
  167. astrbot/core/provider/sources/gemini_source.py +72 -58
  168. astrbot/core/provider/sources/gemini_tts_source.py +8 -6
  169. astrbot/core/provider/sources/gsv_selfhosted_source.py +17 -14
  170. astrbot/core/provider/sources/gsvi_tts_source.py +11 -7
  171. astrbot/core/provider/sources/minimax_tts_api_source.py +50 -40
  172. astrbot/core/provider/sources/openai_embedding_source.py +6 -8
  173. astrbot/core/provider/sources/openai_source.py +102 -69
  174. astrbot/core/provider/sources/openai_tts_api_source.py +14 -6
  175. astrbot/core/provider/sources/sensevoice_selfhosted_source.py +13 -11
  176. astrbot/core/provider/sources/vllm_rerank_source.py +10 -4
  177. astrbot/core/provider/sources/volcengine_tts.py +38 -31
  178. astrbot/core/provider/sources/whisper_api_source.py +14 -12
  179. astrbot/core/provider/sources/whisper_selfhosted_source.py +15 -11
  180. astrbot/core/provider/sources/xinference_rerank_source.py +116 -0
  181. astrbot/core/provider/sources/xinference_stt_provider.py +197 -0
  182. astrbot/core/star/__init__.py +16 -11
  183. astrbot/core/star/config.py +10 -15
  184. astrbot/core/star/context.py +109 -84
  185. astrbot/core/star/filter/__init__.py +4 -3
  186. astrbot/core/star/filter/command.py +30 -28
  187. astrbot/core/star/filter/command_group.py +27 -24
  188. astrbot/core/star/filter/custom_filter.py +6 -5
  189. astrbot/core/star/filter/event_message_type.py +4 -2
  190. astrbot/core/star/filter/permission.py +4 -2
  191. astrbot/core/star/filter/platform_adapter_type.py +4 -2
  192. astrbot/core/star/filter/regex.py +4 -2
  193. astrbot/core/star/register/__init__.py +19 -19
  194. astrbot/core/star/register/star.py +6 -2
  195. astrbot/core/star/register/star_handler.py +96 -73
  196. astrbot/core/star/session_llm_manager.py +48 -14
  197. astrbot/core/star/session_plugin_manager.py +29 -15
  198. astrbot/core/star/star.py +1 -2
  199. astrbot/core/star/star_handler.py +13 -8
  200. astrbot/core/star/star_manager.py +151 -59
  201. astrbot/core/star/star_tools.py +44 -37
  202. astrbot/core/star/updator.py +10 -10
  203. astrbot/core/umop_config_router.py +10 -4
  204. astrbot/core/updator.py +13 -5
  205. astrbot/core/utils/astrbot_path.py +3 -5
  206. astrbot/core/utils/dify_api_client.py +33 -15
  207. astrbot/core/utils/io.py +66 -42
  208. astrbot/core/utils/log_pipe.py +1 -1
  209. astrbot/core/utils/metrics.py +7 -7
  210. astrbot/core/utils/path_util.py +15 -16
  211. astrbot/core/utils/pip_installer.py +5 -5
  212. astrbot/core/utils/session_waiter.py +19 -20
  213. astrbot/core/utils/shared_preferences.py +45 -20
  214. astrbot/core/utils/t2i/__init__.py +4 -1
  215. astrbot/core/utils/t2i/network_strategy.py +35 -26
  216. astrbot/core/utils/t2i/renderer.py +11 -5
  217. astrbot/core/utils/t2i/template_manager.py +14 -15
  218. astrbot/core/utils/tencent_record_helper.py +19 -13
  219. astrbot/core/utils/version_comparator.py +10 -13
  220. astrbot/core/zip_updator.py +43 -40
  221. astrbot/dashboard/routes/__init__.py +18 -18
  222. astrbot/dashboard/routes/auth.py +10 -8
  223. astrbot/dashboard/routes/chat.py +30 -21
  224. astrbot/dashboard/routes/config.py +92 -75
  225. astrbot/dashboard/routes/conversation.py +46 -39
  226. astrbot/dashboard/routes/file.py +4 -2
  227. astrbot/dashboard/routes/knowledge_base.py +47 -40
  228. astrbot/dashboard/routes/log.py +9 -4
  229. astrbot/dashboard/routes/persona.py +19 -16
  230. astrbot/dashboard/routes/plugin.py +69 -55
  231. astrbot/dashboard/routes/route.py +3 -1
  232. astrbot/dashboard/routes/session_management.py +130 -116
  233. astrbot/dashboard/routes/stat.py +34 -34
  234. astrbot/dashboard/routes/t2i.py +15 -12
  235. astrbot/dashboard/routes/tools.py +47 -52
  236. astrbot/dashboard/routes/update.py +32 -28
  237. astrbot/dashboard/server.py +30 -26
  238. astrbot/dashboard/utils.py +8 -4
  239. {astrbot-4.5.0.dist-info → astrbot-4.5.2.dist-info}/METADATA +4 -2
  240. astrbot-4.5.2.dist-info/RECORD +261 -0
  241. astrbot-4.5.0.dist-info/RECORD +0 -258
  242. {astrbot-4.5.0.dist-info → astrbot-4.5.2.dist-info}/WHEEL +0 -0
  243. {astrbot-4.5.0.dist-info → astrbot-4.5.2.dist-info}/entry_points.txt +0 -0
  244. {astrbot-4.5.0.dist-info → astrbot-4.5.2.dist-info}/licenses/LICENSE +0 -0
@@ -1,6 +1,4 @@
1
- """
2
- 会话服务管理器 - 负责管理每个会话的LLM、TTS等服务的启停状态
3
- """
1
+ """会话服务管理器 - 负责管理每个会话的LLM、TTS等服务的启停状态"""
4
2
 
5
3
  from astrbot.core import logger, sp
6
4
  from astrbot.core.platform.astr_message_event import AstrMessageEvent
@@ -22,10 +20,14 @@ class SessionServiceManager:
22
20
 
23
21
  Returns:
24
22
  bool: True表示启用,False表示禁用
23
+
25
24
  """
26
25
  # 获取会话服务配置
27
26
  session_services = sp.get(
28
- "session_service_config", {}, scope="umo", scope_id=session_id
27
+ "session_service_config",
28
+ {},
29
+ scope="umo",
30
+ scope_id=session_id,
29
31
  )
30
32
 
31
33
  # 如果配置了该会话的LLM状态,返回该状态
@@ -43,13 +45,17 @@ class SessionServiceManager:
43
45
  Args:
44
46
  session_id: 会话ID (unified_msg_origin)
45
47
  enabled: True表示启用,False表示禁用
48
+
46
49
  """
47
50
  session_config = (
48
51
  sp.get("session_service_config", {}, scope="umo", scope_id=session_id) or {}
49
52
  )
50
53
  session_config["llm_enabled"] = enabled
51
54
  sp.put(
52
- "session_service_config", session_config, scope="umo", scope_id=session_id
55
+ "session_service_config",
56
+ session_config,
57
+ scope="umo",
58
+ scope_id=session_id,
53
59
  )
54
60
 
55
61
  @staticmethod
@@ -61,6 +67,7 @@ class SessionServiceManager:
61
67
 
62
68
  Returns:
63
69
  bool: True表示应该处理,False表示跳过
70
+
64
71
  """
65
72
  session_id = event.unified_msg_origin
66
73
  return SessionServiceManager.is_llm_enabled_for_session(session_id)
@@ -78,10 +85,14 @@ class SessionServiceManager:
78
85
 
79
86
  Returns:
80
87
  bool: True表示启用,False表示禁用
88
+
81
89
  """
82
90
  # 获取会话服务配置
83
91
  session_services = sp.get(
84
- "session_service_config", {}, scope="umo", scope_id=session_id
92
+ "session_service_config",
93
+ {},
94
+ scope="umo",
95
+ scope_id=session_id,
85
96
  )
86
97
 
87
98
  # 如果配置了该会话的TTS状态,返回该状态
@@ -99,17 +110,21 @@ class SessionServiceManager:
99
110
  Args:
100
111
  session_id: 会话ID (unified_msg_origin)
101
112
  enabled: True表示启用,False表示禁用
113
+
102
114
  """
103
115
  session_config = (
104
116
  sp.get("session_service_config", {}, scope="umo", scope_id=session_id) or {}
105
117
  )
106
118
  session_config["tts_enabled"] = enabled
107
119
  sp.put(
108
- "session_service_config", session_config, scope="umo", scope_id=session_id
120
+ "session_service_config",
121
+ session_config,
122
+ scope="umo",
123
+ scope_id=session_id,
109
124
  )
110
125
 
111
126
  logger.info(
112
- f"会话 {session_id} 的TTS状态已更新为: {'启用' if enabled else '禁用'}"
127
+ f"会话 {session_id} 的TTS状态已更新为: {'启用' if enabled else '禁用'}",
113
128
  )
114
129
 
115
130
  @staticmethod
@@ -121,6 +136,7 @@ class SessionServiceManager:
121
136
 
122
137
  Returns:
123
138
  bool: True表示应该处理,False表示跳过
139
+
124
140
  """
125
141
  session_id = event.unified_msg_origin
126
142
  return SessionServiceManager.is_tts_enabled_for_session(session_id)
@@ -138,10 +154,14 @@ class SessionServiceManager:
138
154
 
139
155
  Returns:
140
156
  bool: True表示启用,False表示禁用
157
+
141
158
  """
142
159
  # 获取会话服务配置
143
160
  session_services = sp.get(
144
- "session_service_config", {}, scope="umo", scope_id=session_id
161
+ "session_service_config",
162
+ {},
163
+ scope="umo",
164
+ scope_id=session_id,
145
165
  )
146
166
 
147
167
  # 如果配置了该会话的整体状态,返回该状态
@@ -159,17 +179,21 @@ class SessionServiceManager:
159
179
  Args:
160
180
  session_id: 会话ID (unified_msg_origin)
161
181
  enabled: True表示启用,False表示禁用
182
+
162
183
  """
163
184
  session_config = (
164
185
  sp.get("session_service_config", {}, scope="umo", scope_id=session_id) or {}
165
186
  )
166
187
  session_config["session_enabled"] = enabled
167
188
  sp.put(
168
- "session_service_config", session_config, scope="umo", scope_id=session_id
189
+ "session_service_config",
190
+ session_config,
191
+ scope="umo",
192
+ scope_id=session_id,
169
193
  )
170
194
 
171
195
  logger.info(
172
- f"会话 {session_id} 的整体状态已更新为: {'启用' if enabled else '禁用'}"
196
+ f"会话 {session_id} 的整体状态已更新为: {'启用' if enabled else '禁用'}",
173
197
  )
174
198
 
175
199
  @staticmethod
@@ -181,6 +205,7 @@ class SessionServiceManager:
181
205
 
182
206
  Returns:
183
207
  bool: True表示应该处理,False表示跳过
208
+
184
209
  """
185
210
  session_id = event.unified_msg_origin
186
211
  return SessionServiceManager.is_session_enabled(session_id)
@@ -198,9 +223,13 @@ class SessionServiceManager:
198
223
 
199
224
  Returns:
200
225
  str: 自定义名称,如果没有设置则返回None
226
+
201
227
  """
202
228
  session_services = sp.get(
203
- "session_service_config", {}, scope="umo", scope_id=session_id
229
+ "session_service_config",
230
+ {},
231
+ scope="umo",
232
+ scope_id=session_id,
204
233
  )
205
234
  return session_services.get("custom_name")
206
235
 
@@ -211,6 +240,7 @@ class SessionServiceManager:
211
240
  Args:
212
241
  session_id: 会话ID (unified_msg_origin)
213
242
  custom_name: 自定义名称,可以为空字符串来清除名称
243
+
214
244
  """
215
245
  session_config = (
216
246
  sp.get("session_service_config", {}, scope="umo", scope_id=session_id) or {}
@@ -221,11 +251,14 @@ class SessionServiceManager:
221
251
  # 如果传入空名称,则删除自定义名称
222
252
  session_config.pop("custom_name", None)
223
253
  sp.put(
224
- "session_service_config", session_config, scope="umo", scope_id=session_id
254
+ "session_service_config",
255
+ session_config,
256
+ scope="umo",
257
+ scope_id=session_id,
225
258
  )
226
259
 
227
260
  logger.info(
228
- f"会话 {session_id} 的自定义名称已更新为: {custom_name.strip() if custom_name and custom_name.strip() else '已清除'}"
261
+ f"会话 {session_id} 的自定义名称已更新为: {custom_name.strip() if custom_name and custom_name.strip() else '已清除'}",
229
262
  )
230
263
 
231
264
  @staticmethod
@@ -237,6 +270,7 @@ class SessionServiceManager:
237
270
 
238
271
  Returns:
239
272
  str: 显示名称
273
+
240
274
  """
241
275
  custom_name = SessionServiceManager.get_session_custom_name(session_id)
242
276
  if custom_name:
@@ -1,9 +1,6 @@
1
- """
2
- 会话插件管理器 - 负责管理每个会话的插件启停状态
3
- """
1
+ """会话插件管理器 - 负责管理每个会话的插件启停状态"""
4
2
 
5
- from astrbot.core import sp, logger
6
- from typing import Dict, List
3
+ from astrbot.core import logger, sp
7
4
  from astrbot.core.platform.astr_message_event import AstrMessageEvent
8
5
 
9
6
 
@@ -20,10 +17,14 @@ class SessionPluginManager:
20
17
 
21
18
  Returns:
22
19
  bool: True表示启用,False表示禁用
20
+
23
21
  """
24
22
  # 获取会话插件配置
25
23
  session_plugin_config = sp.get(
26
- "session_plugin_config", {}, scope="umo", scope_id=session_id
24
+ "session_plugin_config",
25
+ {},
26
+ scope="umo",
27
+ scope_id=session_id,
27
28
  )
28
29
  session_config = session_plugin_config.get(session_id, {})
29
30
 
@@ -43,7 +44,9 @@ class SessionPluginManager:
43
44
 
44
45
  @staticmethod
45
46
  def set_plugin_status_for_session(
46
- session_id: str, plugin_name: str, enabled: bool
47
+ session_id: str,
48
+ plugin_name: str,
49
+ enabled: bool,
47
50
  ) -> None:
48
51
  """设置插件在指定会话中的启停状态
49
52
 
@@ -51,10 +54,14 @@ class SessionPluginManager:
51
54
  session_id: 会话ID (unified_msg_origin)
52
55
  plugin_name: 插件名称
53
56
  enabled: True表示启用,False表示禁用
57
+
54
58
  """
55
59
  # 获取当前配置
56
60
  session_plugin_config = sp.get(
57
- "session_plugin_config", {}, scope="umo", scope_id=session_id
61
+ "session_plugin_config",
62
+ {},
63
+ scope="umo",
64
+ scope_id=session_id,
58
65
  )
59
66
  if session_id not in session_plugin_config:
60
67
  session_plugin_config[session_id] = {
@@ -91,11 +98,11 @@ class SessionPluginManager:
91
98
  )
92
99
 
93
100
  logger.info(
94
- f"会话 {session_id} 的插件 {plugin_name} 状态已更新为: {'启用' if enabled else '禁用'}"
101
+ f"会话 {session_id} 的插件 {plugin_name} 状态已更新为: {'启用' if enabled else '禁用'}",
95
102
  )
96
103
 
97
104
  @staticmethod
98
- def get_session_plugin_config(session_id: str) -> Dict[str, List[str]]:
105
+ def get_session_plugin_config(session_id: str) -> dict[str, list[str]]:
99
106
  """获取指定会话的插件配置
100
107
 
101
108
  Args:
@@ -103,16 +110,21 @@ class SessionPluginManager:
103
110
 
104
111
  Returns:
105
112
  Dict[str, List[str]]: 包含enabled_plugins和disabled_plugins的字典
113
+
106
114
  """
107
115
  session_plugin_config = sp.get(
108
- "session_plugin_config", {}, scope="umo", scope_id=session_id
116
+ "session_plugin_config",
117
+ {},
118
+ scope="umo",
119
+ scope_id=session_id,
109
120
  )
110
121
  return session_plugin_config.get(
111
- session_id, {"enabled_plugins": [], "disabled_plugins": []}
122
+ session_id,
123
+ {"enabled_plugins": [], "disabled_plugins": []},
112
124
  )
113
125
 
114
126
  @staticmethod
115
- def filter_handlers_by_session(event: AstrMessageEvent, handlers: List) -> List:
127
+ def filter_handlers_by_session(event: AstrMessageEvent, handlers: list) -> list:
116
128
  """根据会话配置过滤处理器列表
117
129
 
118
130
  Args:
@@ -121,6 +133,7 @@ class SessionPluginManager:
121
133
 
122
134
  Returns:
123
135
  List: 过滤后的处理器列表
136
+
124
137
  """
125
138
  from astrbot.core.star.star import star_map
126
139
 
@@ -145,12 +158,13 @@ class SessionPluginManager:
145
158
 
146
159
  # 检查插件是否在当前会话中启用
147
160
  if SessionPluginManager.is_plugin_enabled_for_session(
148
- session_id, plugin.name
161
+ session_id,
162
+ plugin.name,
149
163
  ):
150
164
  filtered_handlers.append(handler)
151
165
  else:
152
166
  logger.debug(
153
- f"插件 {plugin.name} 在会话 {session_id} 中被禁用,跳过处理器 {handler.handler_name}"
167
+ f"插件 {plugin.name} 在会话 {session_id} 中被禁用,跳过处理器 {handler.handler_name}",
154
168
  )
155
169
 
156
170
  return filtered_handlers
astrbot/core/star/star.py CHANGED
@@ -16,8 +16,7 @@ if TYPE_CHECKING:
16
16
 
17
17
  @dataclass
18
18
  class StarMetadata:
19
- """
20
- 插件的元数据。
19
+ """插件的元数据。
21
20
 
22
21
  当 activated 为 False 时,star_cls 可能为 None,请不要在插件未激活时调用 star_cls 的方法。
23
22
  """
@@ -1,7 +1,10 @@
1
1
  from __future__ import annotations
2
+
2
3
  import enum
4
+ from collections.abc import Awaitable, Callable
3
5
  from dataclasses import dataclass, field
4
- from typing import Callable, Awaitable, Any, List, Dict, TypeVar, Generic
6
+ from typing import Any, Generic, TypeVar
7
+
5
8
  from .filter import HandlerFilter
6
9
  from .star import star_map
7
10
 
@@ -10,8 +13,8 @@ T = TypeVar("T", bound="StarHandlerMetadata")
10
13
 
11
14
  class StarHandlerRegistry(Generic[T]):
12
15
  def __init__(self):
13
- self.star_handlers_map: Dict[str, StarHandlerMetadata] = {}
14
- self._handlers: List[StarHandlerMetadata] = []
16
+ self.star_handlers_map: dict[str, StarHandlerMetadata] = {}
17
+ self._handlers: list[StarHandlerMetadata] = []
15
18
 
16
19
  def append(self, handler: StarHandlerMetadata):
17
20
  """添加一个 Handler,并保持按优先级有序"""
@@ -31,7 +34,7 @@ class StarHandlerRegistry(Generic[T]):
31
34
  event_type: EventType,
32
35
  only_activated=True,
33
36
  plugins_name: list[str] | None = None,
34
- ) -> List[StarHandlerMetadata]:
37
+ ) -> list[StarHandlerMetadata]:
35
38
  handlers = []
36
39
  for handler in self._handlers:
37
40
  # 过滤事件类型
@@ -64,8 +67,9 @@ class StarHandlerRegistry(Generic[T]):
64
67
  return self.star_handlers_map.get(full_name, None)
65
68
 
66
69
  def get_handlers_by_module_name(
67
- self, module_name: str
68
- ) -> List[StarHandlerMetadata]:
70
+ self,
71
+ module_name: str,
72
+ ) -> list[StarHandlerMetadata]:
69
73
  return [
70
74
  handler
71
75
  for handler in self._handlers
@@ -126,7 +130,7 @@ class StarHandlerMetadata:
126
130
  handler: Callable[..., Awaitable[Any]]
127
131
  """Handler 的函数对象,应当是一个异步函数"""
128
132
 
129
- event_filters: List[HandlerFilter]
133
+ event_filters: list[HandlerFilter]
130
134
  """一个适配器消息事件过滤器,用于描述这个 Handler 能够处理、应该处理的适配器消息事件"""
131
135
 
132
136
  desc: str = ""
@@ -138,5 +142,6 @@ class StarHandlerMetadata:
138
142
  def __lt__(self, other: StarHandlerMetadata):
139
143
  """定义小于运算符以支持优先队列"""
140
144
  return self.extras_configs.get("priority", 0) < other.extras_configs.get(
141
- "priority", 0
145
+ "priority",
146
+ 0,
142
147
  )