mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 02:20:17 +08:00
Introduces PocketBase as an optional sidecar for authentication and session/KB storage, activated only when POCKETBASE_URL is set in .env. Falls back to the existing SQLite/JSON backend when not configured. Backend: - SessionStoreProtocol (typing.Protocol) + get_session_store() factory - PocketBaseSessionStore: JSONL write-ahead buffer, batch-flush on turn end - pocketbase_client.py: singleton admin client, 60s in-memory token cache - auth.py: additive PocketBase path (email-based login/register) - CORS: explicit origins instead of wildcard (wildcard+credentials fails) - WebSocket: validate token at connect time when AUTH_ENABLED Infrastructure: - docker-compose: pocketbase service with healthcheck + depends_on - scripts/pb_setup.py: idempotent PocketBase collection bootstrap - requirements/server.txt: pocketbase>=0.12.0 Frontend: - Register/login: username field -> email field for PocketBase mode - auth.ts: normalise FastAPI 422 errors to plain strings - agents page: guard bots.map() against non-array responses - settings page: graceful fetch error handling - *.env.local added to .gitignore Docs: README PocketBase sidecar setup section added
55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
"""
|
|
Session Management Module
|
|
=========================
|
|
|
|
Provides unified session management for all agent modules.
|
|
|
|
Usage:
|
|
from deeptutor.services.session import BaseSessionManager
|
|
|
|
class MySessionManager(BaseSessionManager):
|
|
def __init__(self):
|
|
super().__init__("my_module")
|
|
|
|
def _get_session_id_prefix(self) -> str:
|
|
return "my_"
|
|
|
|
def _get_default_title(self) -> str:
|
|
return "New My Session"
|
|
|
|
# ... implement other abstract methods
|
|
"""
|
|
|
|
from .base_session_manager import BaseSessionManager
|
|
from .protocol import SessionStoreProtocol
|
|
from .sqlite_store import SQLiteSessionStore, get_sqlite_session_store
|
|
from .turn_runtime import TurnRuntimeManager, get_turn_runtime_manager
|
|
|
|
|
|
def get_session_store() -> SessionStoreProtocol:
|
|
"""
|
|
Return the active session store backend.
|
|
|
|
When POCKETBASE_URL is set in the environment, returns a
|
|
PocketBaseSessionStore. Otherwise falls back to the local
|
|
SQLiteSessionStore (default, zero-config behaviour).
|
|
"""
|
|
import os
|
|
|
|
if os.getenv("POCKETBASE_URL"):
|
|
from .pocketbase_store import PocketBaseSessionStore
|
|
|
|
return PocketBaseSessionStore()
|
|
return get_sqlite_session_store()
|
|
|
|
|
|
__all__ = [
|
|
"BaseSessionManager",
|
|
"SessionStoreProtocol",
|
|
"SQLiteSessionStore",
|
|
"TurnRuntimeManager",
|
|
"get_session_store",
|
|
"get_sqlite_session_store",
|
|
"get_turn_runtime_manager",
|
|
]
|