Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

697 B
Raw Blame
"""Per-response authorizations for trusted templates and their UI bindings."""

from dataclasses import dataclass
import secrets


@dataclass(frozen=True)
class TemplateSecurityContext:
    nonce: str
    event_token: str


def template_security_context(scope: dict) -> TemplateSecurityContext:
    """Keep request state on the request scope, outside shared app state."""
    context = scope.get("_ldr_template_security")
    if not isinstance(context, TemplateSecurityContext):
        context = TemplateSecurityContext(
            nonce=secrets.token_urlsafe(32),
            event_token=secrets.token_urlsafe(32),
        )
        scope["_ldr_template_security"] = context
    return context