# Optional overlay: docker compose -f docker-compose.yml -f openwebui/docker-compose.openwebui.yml up -d
services:
  openwebui:
    image: ghcr.io/open-webui/open-webui:main
    restart: unless-stopped
    environment:
      WEBUI_AUTH: "true"
      WEBUI_AUTH_TRUSTED_EMAIL_HEADER: X-Ulti-User-Email
      WEBUI_AUTH_TRUSTED_NAME_HEADER: X-Ulti-User-Name
      WEBUI_AUTH_TRUSTED_ROLE_HEADER: X-Ulti-User-Role
      ENABLE_PERSISTENT_CONFIG: "false"
      ENABLE_DIRECT_CONNECTIONS: "false"
      ENABLE_FORWARD_USER_INFO_HEADERS: "true"
      # Polling fallback — more reliable than websocket-only through nginx + iframe embed
      ENABLE_WEBSOCKET_SUPPORT: "false"
      BYPASS_MODEL_ACCESS_CONTROL: "true"
      WEBUI_NAME: UltiAI
      OPENAI_API_BASE_URL: http://ultid:8080/api/v1/ai
      OPENAI_API_KEY: ${AI_GATEWAY_API_KEY:-ulti-gateway}
      WEBUI_URL: ${OPENWEBUI_PUBLIC_URL:-http://localhost/ai}
      WEBUI_SECRET_KEY: ${WEBUI_SECRET_KEY:-changeme-openwebui-dev-secret}
      DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/openwebui
      USER_PERMISSIONS_CHAT_TEMPORARY_ENFORCED: "false"
      ENABLE_MCP: "true"
      MCP_INITIALIZE_TIMEOUT: "30"
      USER_PERMISSIONS_FEATURES_DIRECT_TOOL_SERVERS: "true"
      DEFAULT_MODEL_PARAMS: '{"function_calling":"native"}'
      DEFAULT_MODEL_METADATA: '{"toolIds":["server:mcp:ultimail"],"capabilities":{"builtin_tools":true}}'
      TOOL_SERVER_CONNECTIONS: >-
        [{"type":"mcp","url":"http://nginx/api/v1/ai/mcp","auth_type":"bearer","key":"${AI_GATEWAY_API_KEY:-ulti-gateway}","config":{"enable":true,"access_grants":[{"principal_type":"user","principal_id":"*","permission":"read"}]},"info":{"id":"ultimail","name":"Ultimail","description":"Mail, drive, contacts, agenda, recherche suite et recherche web"}}]
    volumes:
      - openwebui_data:/app/backend/data
      - ../services/openwebui/pipelines:/app/pipelines/custom:ro
      - ../services/openwebui/static/logo.png:/app/backend/open_webui/static/logo.png:ro
      - ../services/openwebui/static/favicon.png:/app/backend/open_webui/static/favicon.png:ro
      - ../services/openwebui/static/favicon.png:/app/backend/open_webui/static/favicon-96x96.png:ro
      - ../services/openwebui/static/favicon.png:/app/backend/open_webui/static/apple-touch-icon.png:ro
      - ../services/openwebui/static/favicon.png:/app/backend/open_webui/static/favicon-dark.png:ro
      - ../services/openwebui/static/ultiai-mark.svg:/app/backend/open_webui/static/favicon.svg:ro
      - ../services/openwebui/static/favicon.ico:/app/backend/open_webui/static/favicon.ico:ro
      - ../services/openwebui/static/custom.css:/app/backend/open_webui/static/custom.css:ro
      - ../services/openwebui/static/ulti-session.js:/app/backend/open_webui/static/ulti-session.js:ro
    networks:
      - ulti-net
    depends_on:
      postgres:
        condition: service_healthy
      ultid:
        condition: service_started

  ultimail-mcp:
    build:
      context: ../services/ultimail-mcp
      dockerfile: Dockerfile
    restart: unless-stopped
    environment:
      ULTID_API_URL: http://ultid:8080/api/v1
      MCP_PORT: "3100"
    networks:
      - ulti-net
    depends_on:
      ultid:
        condition: service_started

volumes:
  openwebui_data:
