# Hive AI Configuration Schema
# Infrastructure as Code (IAC) Template  
# Version: 2.0 - With HTTP+SSE MCP Transport Support
# 
# New Features:
# - HTTP+SSE Streamable transport for real-time streaming
# - Multi-IDE support (Claude Code, VS Code, Cursor, Windsurf)
# - Advanced MCP server configuration and port management
# - Security features for HTTP transport (CORS, rate limiting)
# - Environment-specific MCP endpoint configurations

# Metadata for configuration tracking
metadata:
  name: "hive-ai-production"
  description: "Production AI consensus configuration"
  version: "1.0.0"
  environment: "production"
  maintainer: "devops@company.com"
  created: "2025-01-01"
  
# License configuration
license:
  # Support environment variable substitution
  key: "${HIVE_LICENSE_KEY}"
  # Optional: validation endpoint override
  validation_endpoint: "${HIVE_LICENSE_ENDPOINT:-default}"

# Provider configurations
providers:
  openrouter:
    api_key: "${OPENROUTER_API_KEY}"
    # Optional: custom endpoint for enterprise
    endpoint: "${OPENROUTER_ENDPOINT:-https://openrouter.ai/api/v1}"
    # Rate limiting configuration
    rate_limit:
      requests_per_minute: 60
      tokens_per_minute: 100000
    # Timeout settings
    timeout:
      connection: 30
      read: 120

# MCP (Model Context Protocol) Transport Configuration
mcp:
  # Transport configuration
  transport:
    # Transport type: http+sse (recommended) or stdio (legacy)
    type: "http+sse"
    # Server port (default: 3000)
    port: "${MCP_SERVER_PORT:-3000}"
    # Auto-detect available ports if configured port is in use
    auto_port_detection: true
    # Port range for auto-detection
    port_range:
      min: 3000
      max: 3100

  # MCP server configuration
  server:
    # Request timeout in milliseconds
    timeout: 30000
    # Maximum concurrent sessions
    max_sessions: 100
    # Session TTL in seconds
    session_ttl: 3600
    # Streaming configuration
    streaming:
      enabled: true
      buffer_size: 1024
      flush_interval: 100

  # IDE integration settings
  ides:
    # Auto-detect installed IDEs
    auto_detection: true
    # Supported IDEs for MCP integration
    supported_ides:
      - "claude-code"
      - "vscode"
      - "cursor"
      - "windsurf"
    # IDE-specific configurations
    configurations:
      - ide: "claude-code"
        enabled: true
        config_path: "~/.claude.json"
      - ide: "vscode"
        enabled: true
        config_path: "~/.vscode/settings.json"
      - ide: "cursor"
        enabled: true
        config_path: "~/.cursor/mcp.json"
      - ide: "windsurf"
        enabled: true
        config_path: "~/.windsurf/mcp-config.json"

  # Security configuration for HTTP transport
  security:
    # CORS origins (for web-based IDEs)
    cors_origins:
      - "vscode-webview://*"
      - "https://claude.ai"
    # Rate limiting
    rate_limiting:
      enabled: true
      requests_per_minute: 120
    # Session security
    session_security:
      secure_ids: true
      ip_validation: false  # Enable in production if needed

  # Health monitoring for MCP server
  health:
    # Enable health endpoint
    endpoint_enabled: true
    # Include detailed metrics in health response
    detailed_metrics: false
    # Health check interval in seconds
    check_interval: 300

# Pipeline profiles for different use cases
pipelines:
  - name: "Expert-Coding"
    description: "Optimized for software development tasks"
    enabled: true
    stages:
      generator: "anthropic/claude-3.5-sonnet"
      refiner: "openai/gpt-4-turbo"
      validator: "google/gemini-pro"
      curator: "anthropic/claude-3-opus"
    # Cost and performance settings
    settings:
      max_tokens: 4096
      temperature: 0.7
      timeout: 180
      
  - name: "Fast-Research"
    description: "Quick research and analysis"
    enabled: true
    stages:
      generator: "openai/gpt-4o-mini"
      refiner: "anthropic/claude-3-haiku"
      validator: "openai/gpt-3.5-turbo"
    settings:
      max_tokens: 2048
      temperature: 0.5
      timeout: 60
      
  - name: "Enterprise-Analysis"
    description: "High-quality enterprise analysis"
    enabled: false  # Can be enabled per environment
    stages:
      generator: "anthropic/claude-3-opus"
      refiner: "openai/gpt-4-turbo"
      validator: "google/gemini-pro-1.5"
      curator: "anthropic/claude-3.5-sonnet"

# Intelligent features configuration
intelligence:
  # AUTO mode for automatic model selection
  mode: "auto"  # or "manual"
  # Cost optimization settings
  cost_optimization:
    enabled: true
    budget_limit: 0.10  # Daily budget in USD
    cost_alerts: true
  # Template maintenance
  template_maintenance:
    auto_update: true
    health_checks: true
    check_interval: "24h"

# Backup and disaster recovery
backup:
  # Multiple backup locations
  locations:
    - name: "Primary-Local"
      path: "/opt/hive-ai/backups"
      type: "local"
      enabled: true
      priority: 1
    - name: "Cloud-OneDrive"
      path: "${ONEDRIVE_PATH}/hive-ai-backups"
      type: "cloud_sync"
      enabled: true
      priority: 2
    - name: "Cloud-S3"
      path: "s3://company-backups/hive-ai"
      type: "s3"
      enabled: false
      credentials:
        access_key: "${AWS_ACCESS_KEY}"
        secret_key: "${AWS_SECRET_KEY}"
        region: "${AWS_REGION:-us-east-1}"
  
  # Backup scheduling
  schedule:
    daily:
      enabled: true
      time: "02:00"
      retention: 7
    weekly:
      enabled: true
      day: "sunday"
      time: "01:00"
      retention: 4
    monthly:
      enabled: true
      date: 1
      time: "00:00"
      retention: 12
    emergency:
      retention: 5
      
  # Backup verification
  verification:
    integrity_check: true
    test_restore: false  # Expensive operation
    
# Security and access control
security:
  # API key rotation
  key_rotation:
    enabled: false
    interval: "90d"
  # Audit logging
  audit:
    enabled: true
    log_path: "/var/log/hive-ai/audit.log"
    retention: "1y"
  # IP restrictions (enterprise feature)
  ip_allowlist:
    enabled: false
    addresses: []

# Monitoring and alerts
monitoring:
  # Health checks
  health_checks:
    enabled: true
    interval: "5m"
    endpoints:
      - "openrouter"
      - "database"
      - "backup_locations"
      - "mcp_server"
  
  # Performance monitoring
  performance:
    enabled: true
    metrics:
      - "response_time"
      - "token_usage"
      - "cost_tracking"
      - "error_rate"
      - "mcp_sessions"
      - "mcp_streaming_performance"
  
  # Alerting configuration
  alerts:
    enabled: true
    channels:
      - type: "email"
        address: "${ALERT_EMAIL}"
      - type: "slack"
        webhook: "${SLACK_WEBHOOK}"
      - type: "pagerduty"
        api_key: "${PAGERDUTY_API_KEY}"
    
    # Alert thresholds
    thresholds:
      error_rate: 5  # Percentage
      response_time: 30  # Seconds
      daily_cost: 1.00  # USD
      
# Development and testing
development:
  # Enable debug mode
  debug: false
  # Mock providers for testing
  mock_providers: false
  # Development-specific settings
  settings:
    log_level: "info"  # debug, info, warn, error
    verbose_output: false

# Environment-specific overrides
# These can be used to override settings per environment
overrides:
  development:
    intelligence:
      cost_optimization:
        budget_limit: 0.01
    backup:
      schedule:
        daily:
          enabled: false
    development:
      debug: true
      mock_providers: true
    mcp:
      transport:
        port: 3000
      server:
        max_sessions: 10
        streaming:
          buffer_size: 512
      security:
        rate_limiting:
          enabled: false
        session_security:
          ip_validation: false
      health:
        detailed_metrics: true
      
  staging:
    pipelines:
      - name: "Enterprise-Analysis"
        enabled: true
    monitoring:
      alerts:
        enabled: false
    mcp:
      transport:
        port: 3001
      server:
        max_sessions: 50
        session_ttl: 1800
      security:
        rate_limiting:
          requests_per_minute: 60
        session_security:
          ip_validation: true
      health:
        detailed_metrics: true
        
  production:
    security:
      audit:
        enabled: true
    monitoring:
      alerts:
        enabled: true
    backup:
      verification:
        test_restore: true
    mcp:
      transport:
        port: 3002
        auto_port_detection: false
      server:
        max_sessions: 200
        session_ttl: 7200
        streaming:
          buffer_size: 2048
          flush_interval: 50
      security:
        cors_origins:
          - "https://app.company.com"
          - "https://ide.company.com"
        rate_limiting:
          enabled: true
          requests_per_minute: 240
        session_security:
          secure_ids: true
          ip_validation: true
      health:
        endpoint_enabled: true
        detailed_metrics: true
        check_interval: 60