File size: 4,358 Bytes
88f3fce |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
"""
Configuration extensions for Cloudflare integration
"""
import os
from typing import Optional
from pydantic import BaseModel, Field
class CloudflareSettings(BaseModel):
"""Cloudflare configuration settings"""
api_token: Optional[str] = Field(
default_factory=lambda: os.getenv("CLOUDFLARE_API_TOKEN"),
description="Cloudflare API token",
)
account_id: Optional[str] = Field(
default_factory=lambda: os.getenv("CLOUDFLARE_ACCOUNT_ID"),
description="Cloudflare account ID",
)
worker_url: Optional[str] = Field(
default_factory=lambda: os.getenv("CLOUDFLARE_WORKER_URL"),
description="Cloudflare Worker URL",
)
# D1 Database settings
d1_database_id: Optional[str] = Field(
default_factory=lambda: os.getenv("CLOUDFLARE_D1_DATABASE_ID"),
description="D1 database ID",
)
# KV Namespace settings
kv_sessions_id: Optional[str] = Field(
default_factory=lambda: os.getenv("CLOUDFLARE_KV_SESSIONS_ID"),
description="KV namespace ID for sessions",
)
kv_cache_id: Optional[str] = Field(
default_factory=lambda: os.getenv("CLOUDFLARE_KV_CACHE_ID"),
description="KV namespace ID for cache",
)
# R2 Bucket settings
r2_storage_bucket: str = Field(
default_factory=lambda: os.getenv(
"CLOUDFLARE_R2_STORAGE_BUCKET", "openmanus-storage"
),
description="R2 storage bucket name",
)
r2_assets_bucket: str = Field(
default_factory=lambda: os.getenv(
"CLOUDFLARE_R2_ASSETS_BUCKET", "openmanus-assets"
),
description="R2 assets bucket name",
)
# Connection settings
timeout: int = Field(default=30, description="Request timeout in seconds")
def is_configured(self) -> bool:
"""Check if minimum Cloudflare configuration is available"""
return bool(self.api_token and self.account_id)
def has_worker(self) -> bool:
"""Check if worker URL is configured"""
return bool(self.worker_url)
def has_d1(self) -> bool:
"""Check if D1 database is configured"""
return bool(self.d1_database_id)
def has_kv(self) -> bool:
"""Check if KV namespaces are configured"""
return bool(self.kv_sessions_id and self.kv_cache_id)
class HuggingFaceSettings(BaseModel):
"""Hugging Face configuration settings"""
token: Optional[str] = Field(
default_factory=lambda: os.getenv("HUGGINGFACE_TOKEN"),
description="Hugging Face API token",
)
cache_dir: str = Field(
default_factory=lambda: os.getenv(
"HF_HOME", "/app/OpenManus/.cache/huggingface"
),
description="Hugging Face cache directory",
)
model_cache_size: int = Field(
default=5, description="Maximum number of models to cache"
)
class DeploymentSettings(BaseModel):
"""Deployment-specific settings"""
environment: str = Field(
default_factory=lambda: os.getenv("ENVIRONMENT", "development"),
description="Deployment environment",
)
debug: bool = Field(
default_factory=lambda: os.getenv("DEBUG", "false").lower() == "true",
description="Enable debug mode",
)
log_level: str = Field(
default_factory=lambda: os.getenv("LOG_LEVEL", "INFO"),
description="Logging level",
)
# Gradio settings
server_name: str = Field(
default_factory=lambda: os.getenv("GRADIO_SERVER_NAME", "0.0.0.0"),
description="Gradio server name",
)
server_port: int = Field(
default_factory=lambda: int(os.getenv("GRADIO_SERVER_PORT", "7860")),
description="Gradio server port",
)
# Security settings
secret_key: Optional[str] = Field(
default_factory=lambda: os.getenv("SECRET_KEY"),
description="Secret key for sessions",
)
jwt_secret: Optional[str] = Field(
default_factory=lambda: os.getenv("JWT_SECRET"),
description="JWT signing secret",
)
# Create global instances
cloudflare_config = CloudflareSettings()
huggingface_config = HuggingFaceSettings()
deployment_config = DeploymentSettings()
|