AstrBot 4.10.1__py3-none-any.whl → 4.10.3__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 (65) hide show
  1. astrbot/builtin_stars/astrbot/long_term_memory.py +186 -0
  2. astrbot/builtin_stars/astrbot/main.py +128 -0
  3. astrbot/builtin_stars/astrbot/metadata.yaml +4 -0
  4. astrbot/builtin_stars/astrbot/process_llm_request.py +245 -0
  5. astrbot/builtin_stars/builtin_commands/commands/__init__.py +31 -0
  6. astrbot/builtin_stars/builtin_commands/commands/admin.py +77 -0
  7. astrbot/builtin_stars/builtin_commands/commands/alter_cmd.py +173 -0
  8. astrbot/builtin_stars/builtin_commands/commands/conversation.py +366 -0
  9. astrbot/builtin_stars/builtin_commands/commands/help.py +88 -0
  10. astrbot/builtin_stars/builtin_commands/commands/llm.py +20 -0
  11. astrbot/builtin_stars/builtin_commands/commands/persona.py +142 -0
  12. astrbot/builtin_stars/builtin_commands/commands/plugin.py +120 -0
  13. astrbot/builtin_stars/builtin_commands/commands/provider.py +329 -0
  14. astrbot/builtin_stars/builtin_commands/commands/setunset.py +36 -0
  15. astrbot/builtin_stars/builtin_commands/commands/sid.py +36 -0
  16. astrbot/builtin_stars/builtin_commands/commands/t2i.py +23 -0
  17. astrbot/builtin_stars/builtin_commands/commands/tool.py +31 -0
  18. astrbot/builtin_stars/builtin_commands/commands/tts.py +36 -0
  19. astrbot/builtin_stars/builtin_commands/commands/utils/rst_scene.py +26 -0
  20. astrbot/builtin_stars/builtin_commands/main.py +237 -0
  21. astrbot/builtin_stars/builtin_commands/metadata.yaml +4 -0
  22. astrbot/builtin_stars/python_interpreter/main.py +537 -0
  23. astrbot/builtin_stars/python_interpreter/metadata.yaml +4 -0
  24. astrbot/builtin_stars/python_interpreter/requirements.txt +1 -0
  25. astrbot/builtin_stars/python_interpreter/shared/api.py +22 -0
  26. astrbot/builtin_stars/reminder/main.py +266 -0
  27. astrbot/builtin_stars/reminder/metadata.yaml +4 -0
  28. astrbot/builtin_stars/session_controller/main.py +114 -0
  29. astrbot/builtin_stars/session_controller/metadata.yaml +5 -0
  30. astrbot/builtin_stars/web_searcher/engines/__init__.py +111 -0
  31. astrbot/builtin_stars/web_searcher/engines/bing.py +30 -0
  32. astrbot/builtin_stars/web_searcher/engines/sogo.py +52 -0
  33. astrbot/builtin_stars/web_searcher/main.py +436 -0
  34. astrbot/builtin_stars/web_searcher/metadata.yaml +4 -0
  35. astrbot/cli/__init__.py +1 -1
  36. astrbot/core/agent/message.py +9 -0
  37. astrbot/core/agent/runners/tool_loop_agent_runner.py +2 -1
  38. astrbot/core/backup/__init__.py +26 -0
  39. astrbot/core/backup/constants.py +77 -0
  40. astrbot/core/backup/exporter.py +476 -0
  41. astrbot/core/backup/importer.py +761 -0
  42. astrbot/core/config/default.py +1 -1
  43. astrbot/core/log.py +1 -1
  44. astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py +1 -1
  45. astrbot/core/pipeline/waking_check/stage.py +2 -1
  46. astrbot/core/provider/entities.py +32 -9
  47. astrbot/core/provider/provider.py +3 -1
  48. astrbot/core/provider/sources/anthropic_source.py +80 -27
  49. astrbot/core/provider/sources/fishaudio_tts_api_source.py +14 -6
  50. astrbot/core/provider/sources/gemini_source.py +75 -26
  51. astrbot/core/provider/sources/openai_source.py +68 -25
  52. astrbot/core/star/command_management.py +45 -4
  53. astrbot/core/star/context.py +1 -1
  54. astrbot/core/star/star_manager.py +11 -13
  55. astrbot/core/utils/astrbot_path.py +34 -0
  56. astrbot/dashboard/routes/__init__.py +2 -0
  57. astrbot/dashboard/routes/backup.py +589 -0
  58. astrbot/dashboard/routes/command.py +2 -1
  59. astrbot/dashboard/routes/log.py +44 -10
  60. astrbot/dashboard/server.py +8 -1
  61. {astrbot-4.10.1.dist-info → astrbot-4.10.3.dist-info}/METADATA +2 -2
  62. {astrbot-4.10.1.dist-info → astrbot-4.10.3.dist-info}/RECORD +65 -26
  63. {astrbot-4.10.1.dist-info → astrbot-4.10.3.dist-info}/WHEEL +0 -0
  64. {astrbot-4.10.1.dist-info → astrbot-4.10.3.dist-info}/entry_points.txt +0 -0
  65. {astrbot-4.10.1.dist-info → astrbot-4.10.3.dist-info}/licenses/LICENSE +0 -0
@@ -90,6 +90,7 @@ async def toggle_command(handler_full_name: str, enabled: bool) -> CommandDescri
90
90
  async def rename_command(
91
91
  handler_full_name: str,
92
92
  new_fragment: str,
93
+ aliases: list[str] | None = None,
93
94
  ) -> CommandDescriptor:
94
95
  descriptor = _build_descriptor_by_full_name(handler_full_name)
95
96
  if not descriptor:
@@ -99,9 +100,24 @@ async def rename_command(
99
100
  if not new_fragment:
100
101
  raise ValueError("指令名不能为空。")
101
102
 
103
+ # 校验主指令名
102
104
  candidate_full = _compose_command(descriptor.parent_signature, new_fragment)
103
105
  if _is_command_in_use(handler_full_name, candidate_full):
104
- raise ValueError("新的指令名已被其他指令占用,请换一个名称。")
106
+ raise ValueError(f"指令名 '{candidate_full}' 已被其他指令占用。")
107
+
108
+ # 校验别名
109
+ if aliases:
110
+ for alias in aliases:
111
+ alias = alias.strip()
112
+ if not alias:
113
+ continue
114
+ alias_full = _compose_command(descriptor.parent_signature, alias)
115
+ if _is_command_in_use(handler_full_name, alias_full):
116
+ raise ValueError(f"别名 '{alias_full}' 已被其他指令占用。")
117
+
118
+ existing_cfg = await db_helper.get_command_config(handler_full_name)
119
+ merged_extra = dict(existing_cfg.extra_data or {}) if existing_cfg else {}
120
+ merged_extra["resolved_aliases"] = aliases or []
105
121
 
106
122
  config = await db_helper.upsert_command_config(
107
123
  handler_full_name=handler_full_name,
@@ -114,7 +130,7 @@ async def rename_command(
114
130
  conflict_key=descriptor.original_command,
115
131
  resolution_strategy="manual_rename",
116
132
  note=None,
117
- extra_data=None,
133
+ extra_data=merged_extra,
118
134
  auto_managed=False,
119
135
  )
120
136
  _bind_descriptor_with_config(descriptor, config)
@@ -363,14 +379,27 @@ def _apply_config_to_descriptor(
363
379
  new_fragment,
364
380
  )
365
381
 
382
+ extra = config.extra_data or {}
383
+ resolved_aliases = extra.get("resolved_aliases")
384
+ if isinstance(resolved_aliases, list):
385
+ descriptor.aliases = [str(x) for x in resolved_aliases if str(x).strip()]
386
+
366
387
 
367
388
  def _apply_config_to_runtime(
368
389
  descriptor: CommandDescriptor,
369
390
  config: CommandConfig,
370
391
  ) -> None:
371
392
  descriptor.handler.enabled = config.enabled
372
- if descriptor.filter_ref and descriptor.current_fragment:
373
- _set_filter_fragment(descriptor.filter_ref, descriptor.current_fragment)
393
+ if descriptor.filter_ref:
394
+ if descriptor.current_fragment:
395
+ _set_filter_fragment(descriptor.filter_ref, descriptor.current_fragment)
396
+ extra = config.extra_data or {}
397
+ resolved_aliases = extra.get("resolved_aliases")
398
+ if isinstance(resolved_aliases, list):
399
+ _set_filter_aliases(
400
+ descriptor.filter_ref,
401
+ [str(x) for x in resolved_aliases if str(x).strip()],
402
+ )
374
403
 
375
404
 
376
405
  def _bind_configs_to_descriptors(
@@ -409,6 +438,18 @@ def _set_filter_fragment(
409
438
  filter_ref._cmpl_cmd_names = None
410
439
 
411
440
 
441
+ def _set_filter_aliases(
442
+ filter_ref: CommandFilter | CommandGroupFilter,
443
+ aliases: list[str],
444
+ ) -> None:
445
+ current_aliases = getattr(filter_ref, "alias", set())
446
+ if set(aliases) == current_aliases:
447
+ return
448
+ setattr(filter_ref, "alias", set(aliases))
449
+ if hasattr(filter_ref, "_cmpl_cmd_names"):
450
+ filter_ref._cmpl_cmd_names = None
451
+
452
+
412
453
  def _is_command_in_use(
413
454
  target_handler_full_name: str,
414
455
  candidate_full_command: str,
@@ -377,7 +377,7 @@ class Context:
377
377
  if not module_path:
378
378
  _parts = []
379
379
  module_part = tool.__module__.split(".")
380
- flags = ["packages", "plugins"]
380
+ flags = ["builtin_stars", "plugins"]
381
381
  for i, part in enumerate(module_part):
382
382
  _parts.append(part)
383
383
  if part in flags and i + 1 < len(module_part):
@@ -18,6 +18,7 @@ from astrbot.core.config.astrbot_config import AstrBotConfig
18
18
  from astrbot.core.provider.register import llm_tools
19
19
  from astrbot.core.utils.astrbot_path import (
20
20
  get_astrbot_config_path,
21
+ get_astrbot_path,
21
22
  get_astrbot_plugin_path,
22
23
  )
23
24
  from astrbot.core.utils.io import remove_dir
@@ -49,13 +50,10 @@ class PluginManager:
49
50
  """存储插件的路径。即 data/plugins"""
50
51
  self.plugin_config_path = get_astrbot_config_path()
51
52
  """存储插件配置的路径。data/config"""
52
- self.reserved_plugin_path = os.path.abspath(
53
- os.path.join(
54
- os.path.dirname(os.path.abspath(__file__)),
55
- "../../../packages",
56
- ),
53
+ self.reserved_plugin_path = os.path.join(
54
+ get_astrbot_path(), "astrbot", "builtin_stars"
57
55
  )
58
- """保留插件的路径。在 packages 目录下"""
56
+ """保留插件的路径。在 astrbot/builtin_stars 目录下"""
59
57
  self.conf_schema_fname = "_conf_schema.json"
60
58
  self.logo_fname = "logo.png"
61
59
  """插件配置 Schema 文件名"""
@@ -252,7 +250,7 @@ class PluginManager:
252
250
  list[str]: 与该插件相关的模块名列表
253
251
 
254
252
  """
255
- prefix = "packages." if is_reserved else "data.plugins."
253
+ prefix = "astrbot.builtin_stars." if is_reserved else "data.plugins."
256
254
  return [
257
255
  key
258
256
  for key in list(sys.modules.keys())
@@ -270,7 +268,7 @@ class PluginManager:
270
268
  可以基于模块名模式或插件目录名移除模块,用于清理插件相关的模块缓存
271
269
 
272
270
  Args:
273
- module_patterns: 要移除的模块名模式列表(例如 ["data.plugins", "packages"])
271
+ module_patterns: 要移除的模块名模式列表(例如 ["data.plugins", "astrbot.builtin_stars"])
274
272
  root_dir_name: 插件根目录名,用于移除与该插件相关的所有模块
275
273
  is_reserved: 插件是否为保留插件(影响模块路径前缀)
276
274
 
@@ -382,9 +380,9 @@ class PluginManager:
382
380
  reserved = plugin_module.get(
383
381
  "reserved",
384
382
  False,
385
- ) # 是否是保留插件。目前在 packages/ 目录下的都是保留插件。保留插件不可以卸载。
383
+ ) # 是否是保留插件。目前在 astrbot/builtin_stars 目录下的都是保留插件。保留插件不可以卸载。
386
384
 
387
- path = "data.plugins." if not reserved else "packages."
385
+ path = "data.plugins." if not reserved else "astrbot.builtin_stars."
388
386
  path += root_dir_name + "." + module_str
389
387
 
390
388
  # 检查是否需要载入指定的插件
@@ -829,7 +827,7 @@ class PluginManager:
829
827
  if (
830
828
  mp
831
829
  and mp.startswith(plugin_module_path)
832
- and not mp.endswith(("packages", "data.plugins"))
830
+ and not mp.endswith(("astrbot.builtin_stars", "data.plugins"))
833
831
  ):
834
832
  to_remove.append(func_tool)
835
833
  for func_tool in to_remove:
@@ -884,7 +882,7 @@ class PluginManager:
884
882
  plugin.module_path
885
883
  and mp
886
884
  and plugin.module_path.startswith(mp)
887
- and not mp.endswith(("packages", "data.plugins"))
885
+ and not mp.endswith(("astrbot.builtin_stars", "data.plugins"))
888
886
  ):
889
887
  func_tool.active = False
890
888
  if func_tool.name not in inactivated_llm_tools:
@@ -933,7 +931,7 @@ class PluginManager:
933
931
  plugin.module_path
934
932
  and mp
935
933
  and plugin.module_path.startswith(mp)
936
- and not mp.endswith(("packages", "data.plugins"))
934
+ and not mp.endswith(("astrbot.builtin_stars", "data.plugins"))
937
935
  and func_tool.name in inactivated_llm_tools
938
936
  ):
939
937
  inactivated_llm_tools.remove(func_tool.name)
@@ -5,6 +5,10 @@
5
5
  数据目录路径:固定为根目录下的 data 目录
6
6
  配置文件路径:固定为数据目录下的 config 目录
7
7
  插件目录路径:固定为数据目录下的 plugins 目录
8
+ 插件数据目录路径:固定为数据目录下的 plugin_data 目录
9
+ T2I 模板目录路径:固定为数据目录下的 t2i_templates 目录
10
+ WebChat 数据目录路径:固定为数据目录下的 webchat 目录
11
+ 临时文件目录路径:固定为数据目录下的 temp 目录
8
12
  """
9
13
 
10
14
  import os
@@ -37,3 +41,33 @@ def get_astrbot_config_path() -> str:
37
41
  def get_astrbot_plugin_path() -> str:
38
42
  """获取Astrbot插件目录路径"""
39
43
  return os.path.realpath(os.path.join(get_astrbot_data_path(), "plugins"))
44
+
45
+
46
+ def get_astrbot_plugin_data_path() -> str:
47
+ """获取Astrbot插件数据目录路径"""
48
+ return os.path.realpath(os.path.join(get_astrbot_data_path(), "plugin_data"))
49
+
50
+
51
+ def get_astrbot_t2i_templates_path() -> str:
52
+ """获取Astrbot T2I 模板目录路径"""
53
+ return os.path.realpath(os.path.join(get_astrbot_data_path(), "t2i_templates"))
54
+
55
+
56
+ def get_astrbot_webchat_path() -> str:
57
+ """获取Astrbot WebChat 数据目录路径"""
58
+ return os.path.realpath(os.path.join(get_astrbot_data_path(), "webchat"))
59
+
60
+
61
+ def get_astrbot_temp_path() -> str:
62
+ """获取Astrbot临时文件目录路径"""
63
+ return os.path.realpath(os.path.join(get_astrbot_data_path(), "temp"))
64
+
65
+
66
+ def get_astrbot_knowledge_base_path() -> str:
67
+ """获取Astrbot知识库根目录路径"""
68
+ return os.path.realpath(os.path.join(get_astrbot_data_path(), "knowledge_base"))
69
+
70
+
71
+ def get_astrbot_backups_path() -> str:
72
+ """获取Astrbot备份目录路径"""
73
+ return os.path.realpath(os.path.join(get_astrbot_data_path(), "backups"))
@@ -1,4 +1,5 @@
1
1
  from .auth import AuthRoute
2
+ from .backup import BackupRoute
2
3
  from .chat import ChatRoute
3
4
  from .command import CommandRoute
4
5
  from .config import ConfigRoute
@@ -17,6 +18,7 @@ from .update import UpdateRoute
17
18
 
18
19
  __all__ = [
19
20
  "AuthRoute",
21
+ "BackupRoute",
20
22
  "ChatRoute",
21
23
  "CommandRoute",
22
24
  "ConfigRoute",