198 lines
4.7 KiB
Python
198 lines
4.7 KiB
Python
from collections.abc import Mapping
|
|
from datetime import datetime
|
|
from types import TracebackType
|
|
from typing import Protocol, TypeAlias
|
|
from uuid import UUID
|
|
|
|
from domain.chat import Chat, ChatAttachmentName, ChatFile
|
|
from domain.sandbox import SandboxSession
|
|
from domain.user import User
|
|
from domain.workspace import Workspace, WorkspaceUsage
|
|
|
|
AttrValue: TypeAlias = str | int | float | bool
|
|
Attrs: TypeAlias = Mapping[str, AttrValue]
|
|
|
|
|
|
class UserRepository(Protocol):
|
|
def get(self, user_id: str) -> User | None: ...
|
|
|
|
def get_by_email(self, email: str) -> User | None: ...
|
|
|
|
def save(self, user: User) -> None: ...
|
|
|
|
|
|
class WorkspaceRepository(Protocol):
|
|
def get(self, workspace_id: UUID) -> Workspace | None: ...
|
|
|
|
def get_by_user_id(self, user_id: UUID) -> Workspace | None: ...
|
|
|
|
def save(self, workspace: Workspace) -> None: ...
|
|
|
|
|
|
class ChatRepository(Protocol):
|
|
def get(self, chat_id: UUID) -> Chat | None: ...
|
|
|
|
def list_by_workspace_id(self, workspace_id: UUID) -> list[Chat]: ...
|
|
|
|
def save(self, chat: Chat) -> None: ...
|
|
|
|
def delete(self, chat_id: UUID) -> None: ...
|
|
|
|
|
|
class ChatFileRepository(Protocol):
|
|
def get(self, file_id: UUID) -> ChatFile | None: ...
|
|
|
|
def get_by_chat_id_and_name(
|
|
self,
|
|
chat_id: UUID,
|
|
name: ChatAttachmentName,
|
|
) -> ChatFile | None: ...
|
|
|
|
def list_by_chat_id(self, chat_id: UUID) -> list[ChatFile]: ...
|
|
|
|
def save(self, chat_file: ChatFile) -> None: ...
|
|
|
|
def delete(self, file_id: UUID) -> None: ...
|
|
|
|
def delete_by_chat_id(self, chat_id: UUID) -> None: ...
|
|
|
|
|
|
class ChatStorage(Protocol):
|
|
def ensure_chat(self, chat: Chat) -> None: ...
|
|
|
|
def read_history(self, chat: Chat) -> str: ...
|
|
|
|
def write_history(self, chat: Chat, content: str) -> None: ...
|
|
|
|
def delete_chat(self, chat: Chat) -> None: ...
|
|
|
|
def write_attachment(
|
|
self,
|
|
chat: Chat,
|
|
file_name: ChatAttachmentName,
|
|
content: bytes,
|
|
) -> int: ...
|
|
|
|
def read_attachment(self, chat: Chat, file_name: ChatAttachmentName) -> bytes: ...
|
|
|
|
def delete_attachment(
|
|
self,
|
|
chat: Chat,
|
|
file_name: ChatAttachmentName,
|
|
) -> None: ...
|
|
|
|
def clear_attachments(self, chat: Chat) -> None: ...
|
|
|
|
|
|
class StorageUsageReader(Protocol):
|
|
def get_workspace_usage(
|
|
self,
|
|
workspace: Workspace,
|
|
chats: list[Chat],
|
|
) -> WorkspaceUsage: ...
|
|
|
|
|
|
class IdGenerator(Protocol):
|
|
def new(self) -> UUID: ...
|
|
|
|
|
|
class SandboxSessionRepository(Protocol):
|
|
def get_active_by_chat_id(self, chat_id: UUID) -> SandboxSession | None: ...
|
|
|
|
def list_expired(self, now: datetime) -> list[SandboxSession]: ...
|
|
|
|
def count_active(self) -> int: ...
|
|
|
|
def save(self, session: SandboxSession) -> None: ...
|
|
|
|
def delete(self, session_id: UUID) -> None: ...
|
|
|
|
|
|
class LockContext(Protocol):
|
|
def __enter__(self) -> None: ...
|
|
|
|
def __exit__(
|
|
self,
|
|
exc_type: type[BaseException] | None,
|
|
exc: BaseException | None,
|
|
traceback: TracebackType | None,
|
|
) -> bool | None: ...
|
|
|
|
|
|
class SandboxLifecycleLocker(Protocol):
|
|
def lock(self, chat_id: UUID) -> LockContext: ...
|
|
|
|
|
|
class SandboxRuntime(Protocol):
|
|
def create(
|
|
self,
|
|
*,
|
|
session_id: UUID,
|
|
chat_id: UUID,
|
|
created_at: datetime,
|
|
expires_at: datetime,
|
|
) -> SandboxSession: ...
|
|
|
|
def stop(self, container_id: str) -> None: ...
|
|
|
|
|
|
class Clock(Protocol):
|
|
def now(self) -> datetime: ...
|
|
|
|
|
|
class Logger(Protocol):
|
|
def debug(self, message: str, attrs: Attrs | None = None) -> None: ...
|
|
|
|
def info(self, message: str, attrs: Attrs | None = None) -> None: ...
|
|
|
|
def warning(self, message: str, attrs: Attrs | None = None) -> None: ...
|
|
|
|
def error(self, message: str, attrs: Attrs | None = None) -> None: ...
|
|
|
|
|
|
class Metrics(Protocol):
|
|
def increment(
|
|
self,
|
|
name: str,
|
|
value: int = 1,
|
|
attrs: Attrs | None = None,
|
|
) -> None: ...
|
|
|
|
def record(
|
|
self,
|
|
name: str,
|
|
value: float,
|
|
attrs: Attrs | None = None,
|
|
) -> None: ...
|
|
|
|
def set(
|
|
self,
|
|
name: str,
|
|
value: int | float,
|
|
attrs: Attrs | None = None,
|
|
) -> None: ...
|
|
|
|
|
|
class Span(Protocol):
|
|
def set_attribute(self, name: str, value: AttrValue) -> None: ...
|
|
|
|
def record_error(self, error: Exception) -> None: ...
|
|
|
|
|
|
class SpanContext(Protocol):
|
|
def __enter__(self) -> Span: ...
|
|
|
|
def __exit__(
|
|
self,
|
|
exc_type: type[BaseException] | None,
|
|
exc: BaseException | None,
|
|
traceback: TracebackType | None,
|
|
) -> bool | None: ...
|
|
|
|
|
|
class Tracer(Protocol):
|
|
def start_span(
|
|
self,
|
|
name: str,
|
|
attrs: Attrs | None = None,
|
|
) -> SpanContext: ...
|