Source code for soulfire.logs_connect

# Generated from soulfire/logs.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 .logs_pb2 import LogRequest, LogResponse, PreviousLogRequest, PreviousLogResponse

if TYPE_CHECKING:
    from collections.abc import AsyncGenerator, AsyncIterator, Iterable, Iterator, 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 LogsService(Protocol): """ Service for accessing SoulFire server logs. Provides both historical log retrieval and real-time log streaming capabilities. All methods require appropriate authentication and permissions based on the requested scope. """
[docs] async def get_previous(self, request: PreviousLogRequest, ctx: RequestContext[PreviousLogRequest, PreviousLogResponse], /) -> PreviousLogResponse: """ Retrieves historical log entries from the server's in-memory log buffer. The server maintains a rolling buffer of the last 300 log entries. Only returns non-personal logs that match the specified scope. Permissions required: - GlobalLogScope: GLOBAL_SUBSCRIBE_LOGS - InstanceLogScope/BotLogScope/InstanceScriptLogScope: INSTANCE_SUBSCRIBE_LOGS for the instance - PersonalLogScope: No special permissions (but returns empty since personal logs are not stored) Errors: - PERMISSION_DENIED: User lacks required permission for the requested scope - INVALID_ARGUMENT: Scope not set or invalid UUID format - INTERNAL: Server error while retrieving logs """ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs] def subscribe(self, request: LogRequest, ctx: RequestContext[LogRequest, LogResponse], /) -> AsyncIterator[LogResponse]: """ Subscribes to a real-time stream of log entries matching the specified scope. The stream remains open until cancelled by the client or the connection is lost. Permissions are re-validated periodically (every 1 second) to handle permission changes. For PersonalLogScope: Receives personal messages directed to the authenticated user. Personal messages are transient and only delivered to active subscribers. Permissions required: - GlobalLogScope: GLOBAL_SUBSCRIBE_LOGS - InstanceLogScope/BotLogScope/InstanceScriptLogScope: INSTANCE_SUBSCRIBE_LOGS for the instance - PersonalLogScope: No special permissions required Errors: - PERMISSION_DENIED: User lacks required permission for the requested scope - INVALID_ARGUMENT: Scope not set or invalid UUID format - INTERNAL: Server error while setting up subscription """ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs] class LogsServiceASGIApplication(ConnectASGIApplication[LogsService]): def __init__( self, service: LogsService | AsyncGenerator[LogsService], *, 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.LogsService/GetPrevious": Endpoint.unary( method=MethodInfo( name="GetPrevious", service_name="soulfire.v1.LogsService", input=PreviousLogRequest, output=PreviousLogResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.UNARY, ), function=svc.get_previous, ), "/soulfire.v1.LogsService/Subscribe": Endpoint.server_stream( method=MethodInfo( name="Subscribe", service_name="soulfire.v1.LogsService", input=LogRequest, output=LogResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.SERVER_STREAM, ), function=svc.subscribe, ), }, 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.LogsService"
[docs] class LogsServiceClient(ConnectClient): """ Service for accessing SoulFire server logs. Provides both historical log retrieval and real-time log streaming capabilities. All methods require appropriate authentication and permissions based on the requested 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 get_previous( self, request: PreviousLogRequest, *, headers: Headers | Mapping[str, str] | None = None, timeout_ms: int | None = None, ) -> PreviousLogResponse: """ Retrieves historical log entries from the server's in-memory log buffer. The server maintains a rolling buffer of the last 300 log entries. Only returns non-personal logs that match the specified scope. Permissions required: - GlobalLogScope: GLOBAL_SUBSCRIBE_LOGS - InstanceLogScope/BotLogScope/InstanceScriptLogScope: INSTANCE_SUBSCRIBE_LOGS for the instance - PersonalLogScope: No special permissions (but returns empty since personal logs are not stored) Errors: - PERMISSION_DENIED: User lacks required permission for the requested scope - INVALID_ARGUMENT: Scope not set or invalid UUID format - INTERNAL: Server error while retrieving logs """ return await self.execute_unary( request=request, method=MethodInfo( name="GetPrevious", service_name="soulfire.v1.LogsService", input=PreviousLogRequest, output=PreviousLogResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.UNARY, ), headers=headers, timeout_ms=timeout_ms, )
[docs] def subscribe( self, request: LogRequest, *, headers: Headers | Mapping[str, str] | None = None, timeout_ms: int | None = None, ) -> AsyncIterator[LogResponse]: """ Subscribes to a real-time stream of log entries matching the specified scope. The stream remains open until cancelled by the client or the connection is lost. Permissions are re-validated periodically (every 1 second) to handle permission changes. For PersonalLogScope: Receives personal messages directed to the authenticated user. Personal messages are transient and only delivered to active subscribers. Permissions required: - GlobalLogScope: GLOBAL_SUBSCRIBE_LOGS - InstanceLogScope/BotLogScope/InstanceScriptLogScope: INSTANCE_SUBSCRIBE_LOGS for the instance - PersonalLogScope: No special permissions required Errors: - PERMISSION_DENIED: User lacks required permission for the requested scope - INVALID_ARGUMENT: Scope not set or invalid UUID format - INTERNAL: Server error while setting up subscription """ return self.execute_server_stream( request=request, method=MethodInfo( name="Subscribe", service_name="soulfire.v1.LogsService", input=LogRequest, output=LogResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.SERVER_STREAM, ), headers=headers, timeout_ms=timeout_ms, )
[docs] class LogsServiceSync(Protocol): """ Service for accessing SoulFire server logs. Provides both historical log retrieval and real-time log streaming capabilities. All methods require appropriate authentication and permissions based on the requested scope. """
[docs] def get_previous(self, request: PreviousLogRequest, ctx: RequestContext[PreviousLogRequest, PreviousLogResponse], /) -> PreviousLogResponse: """ Retrieves historical log entries from the server's in-memory log buffer. The server maintains a rolling buffer of the last 300 log entries. Only returns non-personal logs that match the specified scope. Permissions required: - GlobalLogScope: GLOBAL_SUBSCRIBE_LOGS - InstanceLogScope/BotLogScope/InstanceScriptLogScope: INSTANCE_SUBSCRIBE_LOGS for the instance - PersonalLogScope: No special permissions (but returns empty since personal logs are not stored) Errors: - PERMISSION_DENIED: User lacks required permission for the requested scope - INVALID_ARGUMENT: Scope not set or invalid UUID format - INTERNAL: Server error while retrieving logs """ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs] def subscribe(self, request: LogRequest, ctx: RequestContext[LogRequest, LogResponse], /) -> Iterator[LogResponse]: """ Subscribes to a real-time stream of log entries matching the specified scope. The stream remains open until cancelled by the client or the connection is lost. Permissions are re-validated periodically (every 1 second) to handle permission changes. For PersonalLogScope: Receives personal messages directed to the authenticated user. Personal messages are transient and only delivered to active subscribers. Permissions required: - GlobalLogScope: GLOBAL_SUBSCRIBE_LOGS - InstanceLogScope/BotLogScope/InstanceScriptLogScope: INSTANCE_SUBSCRIBE_LOGS for the instance - PersonalLogScope: No special permissions required Errors: - PERMISSION_DENIED: User lacks required permission for the requested scope - INVALID_ARGUMENT: Scope not set or invalid UUID format - INTERNAL: Server error while setting up subscription """ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs] class LogsServiceWSGIApplication(ConnectWSGIApplication): def __init__( self, service: LogsServiceSync, 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.LogsService/GetPrevious": EndpointSync.unary( method=MethodInfo( name="GetPrevious", service_name="soulfire.v1.LogsService", input=PreviousLogRequest, output=PreviousLogResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.UNARY, ), function=service.get_previous, ), "/soulfire.v1.LogsService/Subscribe": EndpointSync.server_stream( method=MethodInfo( name="Subscribe", service_name="soulfire.v1.LogsService", input=LogRequest, output=LogResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.SERVER_STREAM, ), function=service.subscribe, ), }, 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.LogsService"
[docs] class LogsServiceClientSync(ConnectClientSync): """ Service for accessing SoulFire server logs. Provides both historical log retrieval and real-time log streaming capabilities. All methods require appropriate authentication and permissions based on the requested 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 get_previous( self, request: PreviousLogRequest, *, headers: Headers | Mapping[str, str] | None = None, timeout_ms: int | None = None, ) -> PreviousLogResponse: """ Retrieves historical log entries from the server's in-memory log buffer. The server maintains a rolling buffer of the last 300 log entries. Only returns non-personal logs that match the specified scope. Permissions required: - GlobalLogScope: GLOBAL_SUBSCRIBE_LOGS - InstanceLogScope/BotLogScope/InstanceScriptLogScope: INSTANCE_SUBSCRIBE_LOGS for the instance - PersonalLogScope: No special permissions (but returns empty since personal logs are not stored) Errors: - PERMISSION_DENIED: User lacks required permission for the requested scope - INVALID_ARGUMENT: Scope not set or invalid UUID format - INTERNAL: Server error while retrieving logs """ return self.execute_unary( request=request, method=MethodInfo( name="GetPrevious", service_name="soulfire.v1.LogsService", input=PreviousLogRequest, output=PreviousLogResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.UNARY, ), headers=headers, timeout_ms=timeout_ms, )
[docs] def subscribe( self, request: LogRequest, *, headers: Headers | Mapping[str, str] | None = None, timeout_ms: int | None = None, ) -> Iterator[LogResponse]: """ Subscribes to a real-time stream of log entries matching the specified scope. The stream remains open until cancelled by the client or the connection is lost. Permissions are re-validated periodically (every 1 second) to handle permission changes. For PersonalLogScope: Receives personal messages directed to the authenticated user. Personal messages are transient and only delivered to active subscribers. Permissions required: - GlobalLogScope: GLOBAL_SUBSCRIBE_LOGS - InstanceLogScope/BotLogScope/InstanceScriptLogScope: INSTANCE_SUBSCRIBE_LOGS for the instance - PersonalLogScope: No special permissions required Errors: - PERMISSION_DENIED: User lacks required permission for the requested scope - INVALID_ARGUMENT: Scope not set or invalid UUID format - INTERNAL: Server error while setting up subscription """ return self.execute_server_stream( request=request, method=MethodInfo( name="Subscribe", service_name="soulfire.v1.LogsService", input=LogRequest, output=LogResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.SERVER_STREAM, ), headers=headers, timeout_ms=timeout_ms, )