mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-16 09:40:30 +08:00
style: 🎨 使用ruff对项目进行format
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
class CommandComponent:
|
||||
pass
|
||||
pass
|
||||
|
||||
@@ -8,20 +8,33 @@ from ...runtime.stars.filter.platform_adapter_type import (
|
||||
PlatformAdapterType,
|
||||
PlatformAdapterTypeFilter,
|
||||
)
|
||||
from ...runtime.stars.registry.register import register_after_message_sent as after_message_sent
|
||||
from ...runtime.stars.registry.register import (
|
||||
register_after_message_sent as after_message_sent,
|
||||
)
|
||||
from ...runtime.stars.registry.register import register_command as command
|
||||
from ...runtime.stars.registry.register import register_command_group as command_group
|
||||
from ...runtime.stars.registry.register import register_custom_filter as custom_filter
|
||||
from ...runtime.stars.registry.register import register_event_message_type as event_message_type
|
||||
from ...runtime.stars.registry.register import (
|
||||
register_event_message_type as event_message_type,
|
||||
)
|
||||
|
||||
# from ...runtime.stars.registry.register import register_llm_tool as llm_tool
|
||||
from ...runtime.stars.registry.register import register_on_astrbot_loaded as on_astrbot_loaded
|
||||
from ...runtime.stars.registry.register import (
|
||||
register_on_astrbot_loaded as on_astrbot_loaded,
|
||||
)
|
||||
from ...runtime.stars.registry.register import (
|
||||
register_on_decorating_result as on_decorating_result,
|
||||
)
|
||||
from ...runtime.stars.registry.register import register_on_llm_request as on_llm_request
|
||||
from ...runtime.stars.registry.register import register_on_llm_response as on_llm_response
|
||||
from ...runtime.stars.registry.register import register_on_platform_loaded as on_platform_loaded
|
||||
from ...runtime.stars.registry.register import register_permission_type as permission_type
|
||||
from ...runtime.stars.registry.register import (
|
||||
register_on_llm_response as on_llm_response,
|
||||
)
|
||||
from ...runtime.stars.registry.register import (
|
||||
register_on_platform_loaded as on_platform_loaded,
|
||||
)
|
||||
from ...runtime.stars.registry.register import (
|
||||
register_permission_type as permission_type,
|
||||
)
|
||||
from ...runtime.stars.registry.register import (
|
||||
register_platform_adapter_type as platform_adapter_type,
|
||||
)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
from .main import cli
|
||||
|
||||
__all__ = ['cli']
|
||||
__all__ = ["cli"]
|
||||
|
||||
@@ -76,6 +76,7 @@ class StarHandlerMetadata:
|
||||
p.pop("event_filters")
|
||||
return p
|
||||
|
||||
|
||||
class StarHandlerRegistry(Generic[T]):
|
||||
def __init__(self):
|
||||
self.star_handlers_map: dict[str, StarHandlerMetadata] = {}
|
||||
|
||||
@@ -25,6 +25,7 @@ from ..filter.platform_adapter_type import (
|
||||
from ..filter.regex import RegexFilter
|
||||
from ..registry import star_handlers_registry, StarHandlerMetadata, EventType
|
||||
|
||||
|
||||
def get_handler_full_name(awaitable: Callable[..., Awaitable[Any]]) -> str:
|
||||
"""获取 Handler 的全名"""
|
||||
return f"{awaitable.__module__}:{awaitable.__qualname__}"
|
||||
|
||||
@@ -24,18 +24,18 @@ class StarManager:
|
||||
root_dir = Path.cwd()
|
||||
else:
|
||||
root_dir = Path(root_dir).resolve()
|
||||
|
||||
|
||||
path = root_dir / "plugin.yaml"
|
||||
if not path.exists():
|
||||
logger.warning("No plugin.yaml found in the current directory.")
|
||||
return []
|
||||
|
||||
|
||||
# Add the plugin directory to sys.path so we can import its modules
|
||||
root_dir_str = str(root_dir)
|
||||
if root_dir_str not in sys.path:
|
||||
sys.path.insert(0, root_dir_str)
|
||||
logger.debug(f"Added {root_dir_str} to sys.path")
|
||||
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
data = yaml.safe_load(f)
|
||||
|
||||
|
||||
@@ -310,7 +310,9 @@ class WorkerRuntime:
|
||||
|
||||
result = response.result
|
||||
if not isinstance(result, dict):
|
||||
raise RuntimeError(f"Invalid handshake payload for plugin {self.plugin.name}")
|
||||
raise RuntimeError(
|
||||
f"Invalid handshake payload for plugin {self.plugin.name}"
|
||||
)
|
||||
|
||||
self.raw_handshake = result
|
||||
self.handlers = self._parse_handlers(result)
|
||||
@@ -493,7 +495,9 @@ class SupervisorRuntime:
|
||||
async def _handle_message(self, message: JSONRPCMessage) -> None:
|
||||
if isinstance(message, JSONRPCRequest):
|
||||
if message.method == "handshake":
|
||||
await self.server.send_message(self._build_handshake_response(message.id))
|
||||
await self.server.send_message(
|
||||
self._build_handshake_response(message.id)
|
||||
)
|
||||
return
|
||||
if message.method == "call_handler":
|
||||
await self._route_call_handler(message)
|
||||
@@ -527,7 +531,9 @@ class SupervisorRuntime:
|
||||
JSONRPCErrorResponse(
|
||||
jsonrpc="2.0",
|
||||
id=message.id,
|
||||
error=JSONRPCErrorData(code=-32602, message=f"Invalid params: {exc}"),
|
||||
error=JSONRPCErrorData(
|
||||
code=-32602, message=f"Invalid params: {exc}"
|
||||
),
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
@@ -5,6 +5,7 @@ from .rpc.jsonrpc import JSONRPCRequest
|
||||
from typing import Any, Literal, Type
|
||||
from ..api.event.astr_message_event import AstrMessageEventModel
|
||||
|
||||
|
||||
class HandshakeRequest(JSONRPCRequest):
|
||||
class Params(BaseModel):
|
||||
pass
|
||||
@@ -34,33 +35,33 @@ class CallHandlerRequest(JSONRPCRequest):
|
||||
|
||||
class HandlerStreamStartNotification(JSONRPCRequest):
|
||||
"""Notification sent when a handler stream starts."""
|
||||
|
||||
|
||||
class Params(BaseModel):
|
||||
id: str | None # The original request ID
|
||||
handler_full_name: str
|
||||
|
||||
|
||||
method: Literal["handler_stream_start"] = "handler_stream_start"
|
||||
params: Params # type: ignore[assignment]
|
||||
|
||||
|
||||
class HandlerStreamUpdateNotification(JSONRPCRequest):
|
||||
"""Notification sent when a handler stream has new data."""
|
||||
|
||||
|
||||
class Params(BaseModel):
|
||||
id: str | None # The original request ID
|
||||
handler_full_name: str
|
||||
data: Any # The streamed data
|
||||
|
||||
|
||||
method: Literal["handler_stream_update"] = "handler_stream_update"
|
||||
params: Params # type: ignore[assignment]
|
||||
|
||||
|
||||
class HandlerStreamEndNotification(JSONRPCRequest):
|
||||
"""Notification sent when a handler stream ends."""
|
||||
|
||||
|
||||
class Params(BaseModel):
|
||||
id: str | None # The original request ID
|
||||
handler_full_name: str
|
||||
|
||||
|
||||
method: Literal["handler_stream_end"] = "handler_stream_end"
|
||||
params: Params # type: ignore[assignment]
|
||||
|
||||
@@ -255,9 +255,7 @@ async def run_benchmark(plugins_dir: Path, python_executable: str) -> dict[str,
|
||||
handshake_error = f"{exc.__class__.__name__}: {exc}"
|
||||
|
||||
measured_at = time.perf_counter()
|
||||
metrics = (
|
||||
collect_process_tree_metrics(client_process.pid) if client_process else {}
|
||||
)
|
||||
metrics = collect_process_tree_metrics(client_process.pid) if client_process else {}
|
||||
loaded_plugins = sorted(
|
||||
metadata_item.name
|
||||
for metadata_item in metadata.values()
|
||||
|
||||
@@ -258,9 +258,7 @@ class SupervisorRuntimeTest(unittest.IsolatedAsyncioTestCase):
|
||||
["plugin_one.main", "plugin_two.main"],
|
||||
)
|
||||
|
||||
handler_full_name = (
|
||||
"commands.plugin_two:SampleCommand.handle_plugin_two"
|
||||
)
|
||||
handler_full_name = "commands.plugin_two:SampleCommand.handle_plugin_two"
|
||||
await self.server.handler(
|
||||
CallHandlerRequest(
|
||||
jsonrpc="2.0",
|
||||
@@ -294,7 +292,9 @@ class SupervisorRuntimeTest(unittest.IsolatedAsyncioTestCase):
|
||||
)
|
||||
)
|
||||
|
||||
self.assertEqual(self.server.sent_messages[-1].result, {"handled_by": "plugin_two"})
|
||||
self.assertEqual(
|
||||
self.server.sent_messages[-1].result, {"handled_by": "plugin_two"}
|
||||
)
|
||||
await runtime.stop()
|
||||
|
||||
async def test_routes_context_response_back_to_matching_worker(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user