Files
DeepTutor/deeptutor/services/session/scope.py
Bingxi Zhao (Frank) da856ad670 release: v1.6.9
Ship folder-based workspaces and data migration, daily practice, redesigned
provider and model settings, and streaming conversation improvements.
Synchronize README translations and document the archive/permanent-delete
upgrade behavior in assets/releases/ver1-6-9.md.

Reduce initial JavaScript by deduplicating English resources and loading
animation features after hydration. Keep the existing route size budgets.
Update regression fixtures and browser audits for scoped URLs and the new
settings and learning interfaces.
2026-09-21 02:30:40 +08:00

60 lines
1.6 KiB
Python

"""Stable process-local identity for session stores and turn runtimes."""
from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
from typing import Any
@dataclass(frozen=True, slots=True)
class StoreScope:
"""A storage backend as seen by one authenticated workspace owner."""
backend: str
resource: str
owner_id: str
@property
def cache_key(self) -> str:
return f"{self.backend}:{self.resource}:{self.owner_id}"
def current_owner_id() -> str:
from deeptutor.multi_user.context import get_current_user
return str(get_current_user().id or "local-admin")
def pocketbase_scope(url: str) -> StoreScope:
from deeptutor.services.workspace.context import current_workspace_id
return StoreScope(
backend="pocketbase",
resource=f"{str(url or '').rstrip('/')}#workspace={current_workspace_id()}",
owner_id=current_owner_id(),
)
def store_scope(store: Any) -> StoreScope:
explicit = getattr(store, "store_scope", None)
if isinstance(explicit, StoreScope):
return explicit
db_path = getattr(store, "db_path", None)
if db_path is not None:
return StoreScope(
backend="sqlite",
resource=str(Path(db_path).resolve()),
owner_id=current_owner_id(),
)
return StoreScope(
backend=f"custom:{type(store).__module__}.{type(store).__qualname__}",
resource=str(getattr(store, "scope_key", "default")),
owner_id=current_owner_id(),
)
__all__ = ["StoreScope", "current_owner_id", "pocketbase_scope", "store_scope"]