Source code for soulfire.command_connect

# Generated from soulfire/command.proto. DO NOT EDIT.
# Generated by protoc-gen-connectrpc-py v0.13.0 with parameter "protobuf=google".
# ruff: noqa: PGH004
# ruff: noqa
# pyright: reportDeprecated=false
# ty: ignore[unused-ignore-comment]
# ty: ignore[deprecated, unused-ignore-comment]
# fmt: off

from __future__ import annotations

from typing import Protocol, TYPE_CHECKING

from connectrpc.client import ConnectClient, ConnectClientSync
from connectrpc.code import Code
from connectrpc.compat import google_protobuf_binary_codec, google_protobuf_codecs
from connectrpc.compression.gzip import GzipCompression
from connectrpc.errors import ConnectError
from connectrpc.method import IdempotencyLevel, MethodInfo, StreamType
from connectrpc.protocol import ProtocolType
from connectrpc.server import ConnectASGIApplication, ConnectWSGIApplication, DEFAULT_READ_MAX_BYTES, Endpoint, EndpointSync
from pyqwest import Client, SyncClient

from .command_pb2 import CommandCompletionRequest, CommandCompletionResponse, CommandRequest, CommandResponse

if TYPE_CHECKING:
    from collections.abc import AsyncGenerator, Iterable, Mapping

    from connectrpc.codec import Codec
    from connectrpc.compression import Compression
    from connectrpc.interceptor import Interceptor, InterceptorSync
    from connectrpc.request import Headers, RequestContext



_DEFAULT_CODECS = google_protobuf_codecs()
_PROTO_BINARY_CODEC = google_protobuf_binary_codec()
_GZIP_COMPRESSION = GzipCompression()

[docs] class CommandService(Protocol): """ Service for executing server commands and retrieving tab-completion suggestions. Commands are executed using the Brigadier command framework and support various operations including bot control, pathfinding, inventory management, and administration. All operations require appropriate permissions based on the specified command scope. """
[docs] async def execute_command(self, request: CommandRequest, ctx: RequestContext[CommandRequest, CommandResponse], /) -> CommandResponse: """ Executes a command string within the specified scope. The command is parsed and executed using the Brigadier command dispatcher. Permission requirements depend on the scope: - Global scope: Requires GLOBAL_COMMAND_EXECUTION permission - Instance scope: Requires INSTANCE_COMMAND_EXECUTION for the instance - Bot scope: Requires INSTANCE_COMMAND_EXECUTION for the parent instance Returns: - CommandResponse with the command's exit code Errors: - INVALID_ARGUMENT: If the scope is not set - PERMISSION_DENIED: If the user lacks required permissions - INTERNAL: If an unexpected error occurs during execution """ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs] async def tab_complete_command(self, request: CommandCompletionRequest, ctx: RequestContext[CommandCompletionRequest, CommandCompletionResponse], /) -> CommandCompletionResponse: """ Retrieves tab-completion suggestions for a partial command. Uses Brigadier's completion system to generate context-aware suggestions based on the command structure and current cursor position. Permission requirements depend on the scope (same as ExecuteCommand). Returns: - CommandCompletionResponse with a list of possible completions Errors: - INVALID_ARGUMENT: If the scope is not set - PERMISSION_DENIED: If the user lacks required permissions - INTERNAL: If an unexpected error occurs during completion """ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs] class CommandServiceASGIApplication(ConnectASGIApplication[CommandService]): def __init__( self, service: CommandService | AsyncGenerator[CommandService], *, interceptors: Iterable[Interceptor] = (), read_max_bytes: int | None = DEFAULT_READ_MAX_BYTES, compressions: Iterable[Compression] | None = None, codecs: Iterable[Codec] | None = _DEFAULT_CODECS, ) -> None: super().__init__( service=service, endpoints=lambda svc: { "/soulfire.v1.CommandService/ExecuteCommand": Endpoint.unary( method=MethodInfo( name="ExecuteCommand", service_name="soulfire.v1.CommandService", input=CommandRequest, output=CommandResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.UNARY, ), function=svc.execute_command, ), "/soulfire.v1.CommandService/TabCompleteCommand": Endpoint.unary( method=MethodInfo( name="TabCompleteCommand", service_name="soulfire.v1.CommandService", input=CommandCompletionRequest, output=CommandCompletionResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.UNARY, ), function=svc.tab_complete_command, ), }, interceptors=interceptors, read_max_bytes=read_max_bytes, compressions=compressions, codecs=codecs, ) @property def path(self) -> str: """Returns the URL path to mount the application to when serving multiple applications.""" return "/soulfire.v1.CommandService"
[docs] class CommandServiceClient(ConnectClient): """ Service for executing server commands and retrieving tab-completion suggestions. Commands are executed using the Brigadier command framework and support various operations including bot control, pathfinding, inventory management, and administration. All operations require appropriate permissions based on the specified command scope. """ def __init__( self, address: str, *, codec: Codec | None = _PROTO_BINARY_CODEC, protocol: ProtocolType = ProtocolType.CONNECT, accept_compression: Iterable[Compression] | None = None, send_compression: Compression | None = _GZIP_COMPRESSION, timeout_ms: int | None = None, read_max_bytes: int | None = None, interceptors: Iterable[Interceptor] = (), http_client: Client | None = None, ) -> None: super().__init__( address=address, codec=codec, protocol=protocol, accept_compression=accept_compression, send_compression=send_compression, timeout_ms=timeout_ms, read_max_bytes=read_max_bytes, interceptors=interceptors, http_client=http_client, )
[docs] async def execute_command( self, request: CommandRequest, *, headers: Headers | Mapping[str, str] | None = None, timeout_ms: int | None = None, ) -> CommandResponse: """ Executes a command string within the specified scope. The command is parsed and executed using the Brigadier command dispatcher. Permission requirements depend on the scope: - Global scope: Requires GLOBAL_COMMAND_EXECUTION permission - Instance scope: Requires INSTANCE_COMMAND_EXECUTION for the instance - Bot scope: Requires INSTANCE_COMMAND_EXECUTION for the parent instance Returns: - CommandResponse with the command's exit code Errors: - INVALID_ARGUMENT: If the scope is not set - PERMISSION_DENIED: If the user lacks required permissions - INTERNAL: If an unexpected error occurs during execution """ return await self.execute_unary( request=request, method=MethodInfo( name="ExecuteCommand", service_name="soulfire.v1.CommandService", input=CommandRequest, output=CommandResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.UNARY, ), headers=headers, timeout_ms=timeout_ms, )
[docs] async def tab_complete_command( self, request: CommandCompletionRequest, *, headers: Headers | Mapping[str, str] | None = None, timeout_ms: int | None = None, ) -> CommandCompletionResponse: """ Retrieves tab-completion suggestions for a partial command. Uses Brigadier's completion system to generate context-aware suggestions based on the command structure and current cursor position. Permission requirements depend on the scope (same as ExecuteCommand). Returns: - CommandCompletionResponse with a list of possible completions Errors: - INVALID_ARGUMENT: If the scope is not set - PERMISSION_DENIED: If the user lacks required permissions - INTERNAL: If an unexpected error occurs during completion """ return await self.execute_unary( request=request, method=MethodInfo( name="TabCompleteCommand", service_name="soulfire.v1.CommandService", input=CommandCompletionRequest, output=CommandCompletionResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.UNARY, ), headers=headers, timeout_ms=timeout_ms, )
[docs] class CommandServiceSync(Protocol): """ Service for executing server commands and retrieving tab-completion suggestions. Commands are executed using the Brigadier command framework and support various operations including bot control, pathfinding, inventory management, and administration. All operations require appropriate permissions based on the specified command scope. """
[docs] def execute_command(self, request: CommandRequest, ctx: RequestContext[CommandRequest, CommandResponse], /) -> CommandResponse: """ Executes a command string within the specified scope. The command is parsed and executed using the Brigadier command dispatcher. Permission requirements depend on the scope: - Global scope: Requires GLOBAL_COMMAND_EXECUTION permission - Instance scope: Requires INSTANCE_COMMAND_EXECUTION for the instance - Bot scope: Requires INSTANCE_COMMAND_EXECUTION for the parent instance Returns: - CommandResponse with the command's exit code Errors: - INVALID_ARGUMENT: If the scope is not set - PERMISSION_DENIED: If the user lacks required permissions - INTERNAL: If an unexpected error occurs during execution """ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs] def tab_complete_command(self, request: CommandCompletionRequest, ctx: RequestContext[CommandCompletionRequest, CommandCompletionResponse], /) -> CommandCompletionResponse: """ Retrieves tab-completion suggestions for a partial command. Uses Brigadier's completion system to generate context-aware suggestions based on the command structure and current cursor position. Permission requirements depend on the scope (same as ExecuteCommand). Returns: - CommandCompletionResponse with a list of possible completions Errors: - INVALID_ARGUMENT: If the scope is not set - PERMISSION_DENIED: If the user lacks required permissions - INTERNAL: If an unexpected error occurs during completion """ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs] class CommandServiceWSGIApplication(ConnectWSGIApplication): def __init__( self, service: CommandServiceSync, interceptors: Iterable[InterceptorSync] = (), read_max_bytes: int | None = DEFAULT_READ_MAX_BYTES, compressions: Iterable[Compression] | None = None, codecs: Iterable[Codec] | None = _DEFAULT_CODECS, ) -> None: super().__init__( endpoints={ "/soulfire.v1.CommandService/ExecuteCommand": EndpointSync.unary( method=MethodInfo( name="ExecuteCommand", service_name="soulfire.v1.CommandService", input=CommandRequest, output=CommandResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.UNARY, ), function=service.execute_command, ), "/soulfire.v1.CommandService/TabCompleteCommand": EndpointSync.unary( method=MethodInfo( name="TabCompleteCommand", service_name="soulfire.v1.CommandService", input=CommandCompletionRequest, output=CommandCompletionResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.UNARY, ), function=service.tab_complete_command, ), }, interceptors=interceptors, read_max_bytes=read_max_bytes, compressions=compressions, codecs=codecs, ) @property def path(self) -> str: """Returns the URL path to mount the application to when serving multiple applications.""" return "/soulfire.v1.CommandService"
[docs] class CommandServiceClientSync(ConnectClientSync): """ Service for executing server commands and retrieving tab-completion suggestions. Commands are executed using the Brigadier command framework and support various operations including bot control, pathfinding, inventory management, and administration. All operations require appropriate permissions based on the specified command scope. """ def __init__( self, address: str, *, codec: Codec | None = _PROTO_BINARY_CODEC, protocol: ProtocolType = ProtocolType.CONNECT, accept_compression: Iterable[Compression] | None = None, send_compression: Compression | None = _GZIP_COMPRESSION, timeout_ms: int | None = None, read_max_bytes: int | None = None, interceptors: Iterable[InterceptorSync] = (), http_client: SyncClient | None = None, ) -> None: super().__init__( address=address, codec=codec, protocol=protocol, accept_compression=accept_compression, send_compression=send_compression, timeout_ms=timeout_ms, read_max_bytes=read_max_bytes, interceptors=interceptors, http_client=http_client, )
[docs] def execute_command( self, request: CommandRequest, *, headers: Headers | Mapping[str, str] | None = None, timeout_ms: int | None = None, ) -> CommandResponse: """ Executes a command string within the specified scope. The command is parsed and executed using the Brigadier command dispatcher. Permission requirements depend on the scope: - Global scope: Requires GLOBAL_COMMAND_EXECUTION permission - Instance scope: Requires INSTANCE_COMMAND_EXECUTION for the instance - Bot scope: Requires INSTANCE_COMMAND_EXECUTION for the parent instance Returns: - CommandResponse with the command's exit code Errors: - INVALID_ARGUMENT: If the scope is not set - PERMISSION_DENIED: If the user lacks required permissions - INTERNAL: If an unexpected error occurs during execution """ return self.execute_unary( request=request, method=MethodInfo( name="ExecuteCommand", service_name="soulfire.v1.CommandService", input=CommandRequest, output=CommandResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.UNARY, ), headers=headers, timeout_ms=timeout_ms, )
[docs] def tab_complete_command( self, request: CommandCompletionRequest, *, headers: Headers | Mapping[str, str] | None = None, timeout_ms: int | None = None, ) -> CommandCompletionResponse: """ Retrieves tab-completion suggestions for a partial command. Uses Brigadier's completion system to generate context-aware suggestions based on the command structure and current cursor position. Permission requirements depend on the scope (same as ExecuteCommand). Returns: - CommandCompletionResponse with a list of possible completions Errors: - INVALID_ARGUMENT: If the scope is not set - PERMISSION_DENIED: If the user lacks required permissions - INTERNAL: If an unexpected error occurs during completion """ return self.execute_unary( request=request, method=MethodInfo( name="TabCompleteCommand", service_name="soulfire.v1.CommandService", input=CommandCompletionRequest, output=CommandCompletionResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.UNARY, ), headers=headers, timeout_ms=timeout_ms, )