Address all architecture review findings: P0 fixes: - Add API key authentication for admin endpoints (analytics, replay, openapi) and WebSocket connections via ADMIN_API_KEY env var - Add PostgreSQL-backed PgSessionManager and PgInterruptManager for multi-worker production deployments (in-memory defaults preserved) P1 fixes: - Implement actual tool generation in OpenAPI approve_job endpoint using generate_tool_code() and generate_agent_yaml() - Add missing clarification, interrupt_expired, and tool_result message handlers in frontend ChatPage P2 fixes: - Replace monkey-patching on CompiledStateGraph with typed GraphContext - Replace 9-param dispatch_message with WebSocketContext dataclass - Extract duplicate _envelope() into shared app/api_utils.py - Replace mutable module-level counter with crypto.randomUUID() - Remove hardcoded mock data from ReviewPage, use api.ts wrappers - Remove `as any` type escape from ReplayPage All 516 tests passing, 0 TypeScript errors.
69 lines
2.0 KiB
Python
69 lines
2.0 KiB
Python
"""Centralized application configuration via pydantic-settings."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Literal
|
|
|
|
from pydantic import model_validator
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(
|
|
env_file=".env",
|
|
env_file_encoding="utf-8",
|
|
extra="ignore",
|
|
)
|
|
|
|
database_url: str
|
|
|
|
llm_provider: Literal["anthropic", "openai", "azure_openai", "google"] = "anthropic"
|
|
llm_model: str = "claude-sonnet-4-6"
|
|
|
|
session_ttl_minutes: int = 30
|
|
interrupt_ttl_minutes: int = 30
|
|
|
|
ws_host: str = "0.0.0.0"
|
|
ws_port: int = 8000
|
|
|
|
webhook_url: str = ""
|
|
webhook_timeout_seconds: int = 10
|
|
webhook_max_retries: int = 3
|
|
|
|
template_name: str = ""
|
|
|
|
admin_api_key: str = ""
|
|
|
|
anthropic_api_key: str = ""
|
|
openai_api_key: str = ""
|
|
azure_openai_api_key: str = ""
|
|
azure_openai_endpoint: str = ""
|
|
azure_openai_api_version: str = "2024-12-01-preview"
|
|
azure_openai_deployment: str = ""
|
|
google_api_key: str = ""
|
|
|
|
@model_validator(mode="after")
|
|
def validate_provider_key(self) -> Settings:
|
|
key_map = {
|
|
"anthropic": self.anthropic_api_key,
|
|
"openai": self.openai_api_key,
|
|
"azure_openai": self.azure_openai_api_key,
|
|
"google": self.google_api_key,
|
|
}
|
|
key = key_map.get(self.llm_provider, "")
|
|
if not key:
|
|
raise ValueError(
|
|
f"API key for provider '{self.llm_provider}' is required. "
|
|
f"Set the corresponding environment variable."
|
|
)
|
|
if self.llm_provider == "azure_openai":
|
|
if not self.azure_openai_endpoint:
|
|
raise ValueError(
|
|
"AZURE_OPENAI_ENDPOINT is required for azure_openai provider."
|
|
)
|
|
if not self.azure_openai_deployment:
|
|
raise ValueError(
|
|
"AZURE_OPENAI_DEPLOYMENT is required for azure_openai provider."
|
|
)
|
|
return self
|