Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
c530489
chore(cli): ruff rewrite
Dt8333 Oct 28, 2025
8b6d235
chore(cli): add missing type annotations
Dt8333 Oct 28, 2025
ffc535f
chore(core.agent): ruff rewrite
Dt8333 Oct 28, 2025
1e59225
chore(core.agent): add missing type annotations
Dt8333 Oct 28, 2025
a60d6fe
fix(core): 重命名__dict__方法避免类型冲突
Dt8333 Oct 28, 2025
5ea6e13
chore(core.config): ruff rewrite
Dt8333 Oct 28, 2025
c414039
chore(core.config): add missing type annotations
Dt8333 Oct 28, 2025
27c815d
chore(core.convmgr): ruff rewrite
Dt8333 Oct 28, 2025
d575969
chore(core.convmgr): add missing type annotations
Dt8333 Oct 28, 2025
b17f50f
chore(core.db): ruff rewrite
Dt8333 Oct 28, 2025
504c6d8
chore(core.db): add missing type annotations
Dt8333 Oct 28, 2025
4a54442
chore(core.kb): ruff rewrite
Dt8333 Oct 28, 2025
556cf55
chore(core.kb): add missing type annotations
Dt8333 Oct 28, 2025
a6bd814
chore(core.db): ruff rewrite missing file
Dt8333 Oct 29, 2025
f0b8020
chore(core.message): ruff rewrite
Dt8333 Oct 29, 2025
ef631ee
chore(core.message): add missing type annotations
Dt8333 Oct 29, 2025
9a6dd40
chore(core.pipeline): ruff rewrite
Dt8333 Oct 29, 2025
d85a395
chore(core.pipeline): add missing type annotations
Dt8333 Oct 29, 2025
9da5d1d
chore(core.platform): ruff rewrite
Dt8333 Oct 29, 2025
b71ba19
chore(core.provider): ruff rewrite
Dt8333 Oct 30, 2025
28d70db
chore(core.star): ruff rewrite
Dt8333 Oct 30, 2025
595f766
chore(core.message): ruff rewrite
Dt8333 Oct 30, 2025
932d76d
chore(core.utils): ruff rewrite
Dt8333 Oct 30, 2025
70a9186
refactor: 为大量构造方法及相关方法添加返回类型 None 注解
Dt8333 Dec 11, 2025
39463e9
refactor: 为大量函数添加返回 None 的类型注解
Dt8333 Dec 11, 2025
8d766f0
refactor: 为 save_mcp_config 添加返回类型注解 bool
Dt8333 Dec 11, 2025
1f2a16c
refactor: 统一 typing 导入顺序并将 NoReturn 导入提前
Dt8333 Dec 11, 2025
1b564f3
refactor: 为多处函数添加返回值/参数类型注解
Dt8333 Dec 11, 2025
dc873ae
feat: 为 build_plug_list 添加 PluginInfo TypedDict 与类型注解
Dt8333 Dec 11, 2025
c0babb0
refactor: 为 display_plugins 增加参数类型注解并导入 PluginInfo
Dt8333 Dec 11, 2025
fb45af4
Merge branch 'ann-old' into chore-ann-fix
Dt8333 Dec 11, 2025
c13f5ab
style: 统一多处函数参数换行与类型注释风格
Dt8333 Dec 11, 2025
1256a66
refactor: 增强类型注解并修正 MCP 客户端与消息模型签名
Dt8333 Dec 12, 2025
ee5eb7b
fix: 统一修复 ANN 注解问题,替换 Any 为 object,完善返回类型
Dt8333 Dec 12, 2025
c5db8a4
fix: 将 KnowledgeBaseQueryTool.call 的 kwargs 标注为 object,并将 query 转为 st…
Dt8333 Dec 12, 2025
9c84007
refactor: 将多处函数参数的 Any 改为 object,统一类型注解
Dt8333 Dec 12, 2025
eda5909
fix: 让 ContentPart.__init_subclass__ 使用 Unpack[ConfigDict] 与类型检查对齐
Dt8333 Dec 17, 2025
1539a3d
refactor: 用 TypedDict+Unpack 重构 HandoffTool __init__ 参数类型
Dt8333 Dec 17, 2025
a230bbd
chore: 移除未使用的 Any 导入并整理导入依赖
Dt8333 Dec 17, 2025
3bd0555
Merge branch 'master' into chore-ann-fix
Dt8333 Dec 17, 2025
80a7e37
refactor: 使用 TypedDict+Unpack 重构 get_filtered_conversations 的 kwargs 类型
Dt8333 Dec 17, 2025
14de584
style: 在 NOT_GIVEN 与 TxResult 之间添加空行以改善可读性
Dt8333 Dec 17, 2025
8fc7f3c
fix: 兼容 Unpack 的 typing 导入
Dt8333 Dec 17, 2025
280a3ed
refactor: 将 chunk 函数改为关键字参数并加入边界处理
Dt8333 Dec 17, 2025
7f89148
fix: 调整 FixedSizeChunker.chunk 签名并实现关键字参数与边界处理
Dt8333 Dec 17, 2025
681b6d1
fix: 将 any 替换为 Any,并导入 typing 的 Any
Dt8333 Dec 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions astrbot/cli/commands/cmd_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _save_config(config: dict[str, Any]) -> None:
)


def _set_nested_item(obj: dict[str, Any], path: str, value: Any) -> None:
def _set_nested_item(obj: dict[str, Any], path: str, value: object) -> None:
"""设置嵌套字典中的值"""
parts = path.split(".")
for part in parts[:-1]:
Expand All @@ -118,7 +118,7 @@ def _set_nested_item(obj: dict[str, Any], path: str, value: Any) -> None:
obj[parts[-1]] = value


def _get_nested_item(obj: dict[str, Any], path: str) -> Any:
def _get_nested_item(obj: dict[str, Any], path: str) -> object:
"""获取嵌套字典中的值"""
parts = path.split(".")
for part in parts:
Expand All @@ -127,7 +127,7 @@ def _get_nested_item(obj: dict[str, Any], path: str) -> Any:


@click.group(name="conf")
def conf():
def conf() -> None:
"""配置管理命令

支持的配置项:
Expand All @@ -149,7 +149,7 @@ def conf():
@conf.command(name="set")
@click.argument("key")
@click.argument("value")
def set_config(key: str, value: str):
def set_config(key: str, value: str) -> None:
"""设置配置项的值"""
if key not in CONFIG_VALIDATORS:
raise click.ClickException(f"不支持的配置项: {key}")
Expand Down Expand Up @@ -178,7 +178,7 @@ def set_config(key: str, value: str):

@conf.command(name="get")
@click.argument("key", required=False)
def get_config(key: str | None = None):
def get_config(key: str | None = None) -> None:
"""获取配置项的值,不提供key则显示所有可配置项"""
config = _load_config()

Expand Down
23 changes: 14 additions & 9 deletions astrbot/cli/commands/cmd_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import click

from ..utils import (
PluginInfo,
PluginStatus,
build_plug_list,
check_astrbot_root,
Expand All @@ -15,7 +16,7 @@


@click.group()
def plug():
def plug() -> None:
"""插件管理"""


Expand All @@ -28,7 +29,11 @@ def _get_data_path() -> Path:
return (base / "data").resolve()


def display_plugins(plugins, title=None, color=None):
def display_plugins(
plugins: list[PluginInfo],
title: str | None = None,
color: int | tuple[int, int, int] | str | None = None,
) -> None:
if title:
click.echo(click.style(title, fg=color, bold=True))

Expand All @@ -45,7 +50,7 @@ def display_plugins(plugins, title=None, color=None):

@plug.command()
@click.argument("name")
def new(name: str):
def new(name: str) -> None:
"""创建新插件"""
base_path = _get_data_path()
plug_path = base_path / "plugins" / name
Expand Down Expand Up @@ -100,7 +105,7 @@ def new(name: str):

@plug.command()
@click.option("--all", "-a", is_flag=True, help="列出未安装的插件")
def list(all: bool):
def list(all: bool) -> None:
"""列出插件"""
base_path = _get_data_path()
plugins = build_plug_list(base_path / "plugins")
Expand Down Expand Up @@ -141,7 +146,7 @@ def list(all: bool):
@plug.command()
@click.argument("name")
@click.option("--proxy", help="代理服务器地址")
def install(name: str, proxy: str | None):
def install(name: str, proxy: str | None) -> None:
"""安装插件"""
base_path = _get_data_path()
plug_path = base_path / "plugins"
Expand All @@ -164,13 +169,13 @@ def install(name: str, proxy: str | None):

@plug.command()
@click.argument("name")
def remove(name: str):
def remove(name: str) -> None:
"""卸载插件"""
base_path = _get_data_path()
plugins = build_plug_list(base_path / "plugins")
plugin = next((p for p in plugins if p["name"] == name), None)

if not plugin or not plugin.get("local_path"):
if not plugin or not plugin["local_path"]:
raise click.ClickException(f"插件 {name} 不存在或未安装")

plugin_path = plugin["local_path"]
Expand All @@ -187,7 +192,7 @@ def remove(name: str):
@plug.command()
@click.argument("name", required=False)
@click.option("--proxy", help="Github代理地址")
def update(name: str, proxy: str | None):
def update(name: str, proxy: str | None) -> None:
"""更新插件"""
base_path = _get_data_path()
plug_path = base_path / "plugins"
Expand Down Expand Up @@ -225,7 +230,7 @@ def update(name: str, proxy: str | None):

@plug.command()
@click.argument("query")
def search(query: str):
def search(query: str) -> None:
"""搜索插件"""
base_path = _get_data_path()
plugins = build_plug_list(base_path / "plugins")
Expand Down
2 changes: 1 addition & 1 deletion astrbot/cli/commands/cmd_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ..utils import check_astrbot_root, check_dashboard, get_astrbot_root


async def run_astrbot(astrbot_root: Path):
async def run_astrbot(astrbot_root: Path) -> None:
"""运行 AstrBot"""
from astrbot.core import LogBroker, LogManager, db_helper, logger
from astrbot.core.initial_loader import InitialLoader
Expand Down
9 changes: 8 additions & 1 deletion astrbot/cli/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
check_dashboard,
get_astrbot_root,
)
from .plugin import PluginStatus, build_plug_list, get_git_repo, manage_plugin
from .plugin import (
PluginInfo,
PluginStatus,
build_plug_list,
get_git_repo,
manage_plugin,
)
from .version_comparator import VersionComparator

__all__ = [
"PluginInfo",
"PluginStatus",
"VersionComparator",
"build_plug_list",
Expand Down
25 changes: 18 additions & 7 deletions astrbot/cli/utils/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from enum import Enum
from io import BytesIO
from pathlib import Path
from typing import TypedDict
from zipfile import ZipFile

import click
Expand All @@ -19,7 +20,17 @@ class PluginStatus(str, Enum):
NOT_PUBLISHED = "未发布"


def get_git_repo(url: str, target_path: Path, proxy: str | None = None):
class PluginInfo(TypedDict):
name: str
desc: str
version: str
author: str
repo: str
status: PluginStatus
local_path: str | None


def get_git_repo(url: str, target_path: Path, proxy: str | None = None) -> None:
"""从 Git 仓库下载代码并解压到指定路径"""
temp_dir = Path(tempfile.mkdtemp())
try:
Expand Down Expand Up @@ -102,18 +113,18 @@ def load_yaml_metadata(plugin_dir: Path) -> dict:
return {}


def build_plug_list(plugins_dir: Path) -> list:
def build_plug_list(plugins_dir: Path) -> list[PluginInfo]:
"""构建插件列表,包含本地和在线插件信息

Args:
plugins_dir (Path): 插件目录路径

Returns:
list: 包含插件信息的字典列表
list[PluginInfo]: 包含插件信息的字典列表

"""
# 获取本地插件信息
result = []
result: list[PluginInfo] = []
if plugins_dir.exists():
for plugin_name in [d.name for d in plugins_dir.glob("*") if d.is_dir()]:
plugin_dir = plugins_dir / plugin_name
Expand Down Expand Up @@ -141,7 +152,7 @@ def build_plug_list(plugins_dir: Path) -> list:
)

# 获取在线插件列表
online_plugins = []
online_plugins: list[PluginInfo] = []
try:
with httpx.Client() as client:
resp = client.get("https://api.soulter.top/astrbot/plugins")
Expand Down Expand Up @@ -191,7 +202,7 @@ def build_plug_list(plugins_dir: Path) -> list:


def manage_plugin(
plugin: dict,
plugin: PluginInfo,
plugins_dir: Path,
is_update: bool = False,
proxy: str | None = None,
Expand All @@ -209,7 +220,7 @@ def manage_plugin(
repo_url = plugin["repo"]

# 如果是更新且有本地路径,直接使用本地路径
if is_update and plugin.get("local_path"):
if is_update and plugin["local_path"]:
target_path = Path(plugin["local_path"])
else:
target_path = plugins_dir / plugin_name
Expand Down
4 changes: 2 additions & 2 deletions astrbot/cli/utils/version_comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def compare_version(v1: str, v2: str) -> int:
v1 = v1.lower().replace("v", "")
v2 = v2.lower().replace("v", "")

def split_version(version):
def split_version(version: str) -> tuple[list[int], list[int | str] | None]:
match = re.match(
r"^([0-9]+(?:\.[0-9]+)*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+(.+))?$",
version,
Expand Down Expand Up @@ -77,7 +77,7 @@ def split_version(version):
return 0 # 数字部分和预发布标签都相同

@staticmethod
def _split_prerelease(prerelease):
def _split_prerelease(prerelease: str) -> list[int | str] | None:
if not prerelease:
return None
parts = prerelease.split(".")
Expand Down
23 changes: 19 additions & 4 deletions astrbot/core/agent/handoff.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
from __future__ import annotations

from collections.abc import AsyncGenerator, Awaitable, Callable
from typing import Generic

from typing_extensions import TypedDict, Unpack

from astrbot.core.message.message_event_result import MessageEventResult

from .agent import Agent
from .run_context import TContext
from .tool import FunctionTool
from .tool import FunctionTool, ParametersType


class HandoffInitKwargs(TypedDict, total=False):
handler: (
Callable[..., Awaitable[str | None] | AsyncGenerator[MessageEventResult]] | None
)
handler_module_path: str | None
active: bool


class HandoffTool(FunctionTool, Generic[TContext]):
Expand All @@ -11,9 +26,9 @@ class HandoffTool(FunctionTool, Generic[TContext]):
def __init__(
self,
agent: Agent[TContext],
parameters: dict | None = None,
**kwargs,
):
parameters: ParametersType | None = None,
**kwargs: Unpack[HandoffInitKwargs],
) -> None:
self.agent = agent
super().__init__(
name=f"transfer_to_{agent.name}",
Expand Down
8 changes: 4 additions & 4 deletions astrbot/core/agent/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@


class BaseAgentRunHooks(Generic[TContext]):
async def on_agent_begin(self, run_context: ContextWrapper[TContext]): ...
async def on_agent_begin(self, run_context: ContextWrapper[TContext]) -> None: ...
async def on_tool_start(
self,
run_context: ContextWrapper[TContext],
tool: FunctionTool,
tool_args: dict | None,
): ...
) -> None: ...
async def on_tool_end(
self,
run_context: ContextWrapper[TContext],
tool: FunctionTool,
tool_args: dict | None,
tool_result: mcp.types.CallToolResult | None,
): ...
) -> None: ...
async def on_agent_done(
self,
run_context: ContextWrapper[TContext],
llm_response: LLMResponse,
): ...
) -> None: ...
Loading