|
| 1 | +# ruff: noqa: E402 |
1 | 2 | from __future__ import annotations |
2 | 3 |
|
3 | 4 | import asyncio |
@@ -45,7 +46,14 @@ def install(name: str, attrs: dict[str, object]) -> None: |
45 | 46 | _install_optional_dependency_stubs() |
46 | 47 |
|
47 | 48 | from astrbot_sdk._internal.invocation_context import current_caller_plugin_id |
| 49 | +from astrbot_sdk._internal.plugin_ids import ( |
| 50 | + capability_belongs_to_plugin, |
| 51 | + http_route_belongs_to_plugin, |
| 52 | + plugin_capability_prefix, |
| 53 | + plugin_http_route_root, |
| 54 | +) |
48 | 55 | from astrbot_sdk.context import Context |
| 56 | +from astrbot_sdk.errors import AstrBotError |
49 | 57 | from astrbot_sdk.message.components import component_to_payload_sync |
50 | 58 | from astrbot_sdk.runtime._streaming import StreamExecution |
51 | 59 |
|
@@ -432,6 +440,21 @@ def register_http_api( |
432 | 440 | ) -> None: |
433 | 441 | normalized_route = self._normalize_route(route) |
434 | 442 | normalized_methods = self._normalize_methods(methods) |
| 443 | + if not http_route_belongs_to_plugin(normalized_route, plugin_id): |
| 444 | + route_root = plugin_http_route_root(plugin_id) |
| 445 | + raise AstrBotError.invalid_input( |
| 446 | + "http.register_api requires route to use the current plugin " |
| 447 | + f"namespace: route={normalized_route!r}, plugin_id={plugin_id!r}, " |
| 448 | + f"expected={route_root!r} or {route_root + '/...'}" |
| 449 | + ) |
| 450 | + if not capability_belongs_to_plugin(str(handler_capability), plugin_id): |
| 451 | + expected_prefix = plugin_capability_prefix(plugin_id) |
| 452 | + raise AstrBotError.invalid_input( |
| 453 | + "http.register_api requires handler_capability to belong to the " |
| 454 | + "current plugin: " |
| 455 | + f"capability={handler_capability!r}, plugin_id={plugin_id!r}, " |
| 456 | + f"expected_prefix={expected_prefix!r}" |
| 457 | + ) |
435 | 458 | existing = [ |
436 | 459 | item |
437 | 460 | for item in self.http_routes.get(plugin_id, []) |
@@ -1055,7 +1078,7 @@ def __init__(self, bridge: CoreCapabilityBridge) -> None: |
1055 | 1078 | self._request_counter = 0 |
1056 | 1079 | self.remote_peer = object() |
1057 | 1080 | self.remote_capability_map = { |
1058 | | - descriptor.name: descriptor for descriptor in bridge.descriptors() |
| 1081 | + descriptor.name: descriptor for descriptor in bridge.all_descriptors() |
1059 | 1082 | } |
1060 | 1083 |
|
1061 | 1084 | def _next_request_id(self) -> str: |
|
0 commit comments