Move the Supabase tenant extension into the hindsight-api package so users can enable it with just an environment variable — no file copying or Docker image modifications needed. Key improvements over the original submission: - JWKS-based local JWT verification (no network call per request) with automatic fallback to /auth/v1/user for legacy HS256 projects - Service key is now optional (only needed for HS256 or health checks) - UUID validation on user IDs before schema name construction - Schema prefix validation against Postgres identifier rules - Key rotation handling with automatic JWKS cache refresh - Proper logging via Python logging module - Tenant extension lifecycle hooks (on_startup/on_shutdown) wired into the server lifespan - Public tenant_extension property on MemoryEngine - 54 unit tests covering both verification modes, cache behavior, error paths, and the extension loader - README updated to reflect JWKS-first architecture Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
89 lines
2.5 KiB
Python
89 lines
2.5 KiB
Python
"""
|
|
Hindsight Extensions System.
|
|
|
|
Extensions allow customizing and extending Hindsight behavior without modifying core code.
|
|
Extensions are loaded via environment variables pointing to implementation classes.
|
|
|
|
Example:
|
|
HINDSIGHT_API_OPERATION_VALIDATOR_EXTENSION=mypackage.validators:MyValidator
|
|
HINDSIGHT_API_OPERATION_VALIDATOR_MAX_RETRIES=3
|
|
|
|
HINDSIGHT_API_HTTP_EXTENSION=mypackage.http:MyHttpExtension
|
|
HINDSIGHT_API_HTTP_SOME_CONFIG=value
|
|
|
|
Extensions receive an ExtensionContext that provides a controlled API for interacting
|
|
with the system (e.g., running migrations for tenant schemas).
|
|
"""
|
|
|
|
from hindsight_api.extensions.base import Extension
|
|
from hindsight_api.extensions.builtin import ApiKeyTenantExtension, SupabaseTenantExtension
|
|
from hindsight_api.extensions.context import DefaultExtensionContext, ExtensionContext
|
|
from hindsight_api.extensions.http import HttpExtension
|
|
from hindsight_api.extensions.loader import load_extension
|
|
from hindsight_api.extensions.mcp import MCPExtension
|
|
from hindsight_api.extensions.operation_validator import (
|
|
# Consolidation operation
|
|
ConsolidateContext,
|
|
ConsolidateResult,
|
|
# Mental Model operations
|
|
MentalModelGetContext,
|
|
MentalModelGetResult,
|
|
MentalModelRefreshContext,
|
|
MentalModelRefreshResult,
|
|
# Core operations
|
|
OperationValidationError,
|
|
OperationValidatorExtension,
|
|
RecallContext,
|
|
RecallResult,
|
|
ReflectContext,
|
|
ReflectResultContext,
|
|
RetainContext,
|
|
RetainResult,
|
|
ValidationResult,
|
|
)
|
|
from hindsight_api.extensions.tenant import (
|
|
AuthenticationError,
|
|
Tenant,
|
|
TenantContext,
|
|
TenantExtension,
|
|
)
|
|
from hindsight_api.models import RequestContext
|
|
|
|
__all__ = [
|
|
# Base
|
|
"Extension",
|
|
"load_extension",
|
|
# Context
|
|
"ExtensionContext",
|
|
"DefaultExtensionContext",
|
|
# HTTP Extension
|
|
"HttpExtension",
|
|
# MCP Extension
|
|
"MCPExtension",
|
|
# Operation Validator - Core
|
|
"OperationValidationError",
|
|
"OperationValidatorExtension",
|
|
"RecallContext",
|
|
"RecallResult",
|
|
"ReflectContext",
|
|
"ReflectResultContext",
|
|
"RetainContext",
|
|
"RetainResult",
|
|
"ValidationResult",
|
|
# Operation Validator - Consolidation
|
|
"ConsolidateContext",
|
|
"ConsolidateResult",
|
|
# Operation Validator - Mental Model
|
|
"MentalModelGetContext",
|
|
"MentalModelGetResult",
|
|
"MentalModelRefreshContext",
|
|
"MentalModelRefreshResult",
|
|
# Tenant/Auth
|
|
"ApiKeyTenantExtension",
|
|
"SupabaseTenantExtension",
|
|
"AuthenticationError",
|
|
"RequestContext",
|
|
"Tenant",
|
|
"TenantContext",
|
|
"TenantExtension",
|
|
]
|