services:
  flynn:
    build: .
    container_name: flynn
    restart: unless-stopped
    ports:
      - "18800:18800"
    volumes:
      # Persistent data (sessions DB, memory store)
      - flynn-data:/data
      # Mount your config file
      - ./config/default.yaml:/config/config.yaml:ro
    environment:
      # Required: at least one model provider API key
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:-}
      # Optional: additional provider keys
      - OPENAI_API_KEY=${OPENAI_API_KEY:-}
      - OPENROUTER_API_KEY=${OPENROUTER_API_KEY:-}
      - GOOGLE_API_KEY=${GOOGLE_API_KEY:-}
      # Optional: Telegram integration
      - FLYNN_TELEGRAM_TOKEN=${FLYNN_TELEGRAM_TOKEN:-}
      # Optional: Discord integration
      - DISCORD_BOT_TOKEN=${DISCORD_BOT_TOKEN:-}
      # Optional: Gateway auth token
      - FLYNN_SERVER_TOKEN=${FLYNN_SERVER_TOKEN:-}
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://localhost:18800/"]
      interval: 30s
      timeout: 5s
      start_period: 15s
      retries: 3

  # Optional local dependency: whisper.cpp server for audio transcription.
  # Start with: docker compose --profile voice up -d whisper-server
  whisper-server:
    image: ghcr.io/ggml-org/whisper.cpp:main
    container_name: whisper-server
    restart: unless-stopped
    profiles: ["voice"]
    ports:
      - "18801:8080"
    volumes:
      - whisper-models:/app/models
    # Override image entrypoint so args are passed directly to whisper-server.
    entrypoint: ["whisper-server"]
    command:
      - --model
      - /app/models/ggml-base.en.bin
      - --host
      - 0.0.0.0
      - --port
      - "8080"
      - --convert
      - --language
      - en
      - --inference-path
      - /v1/audio/transcriptions
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:8080/ >/dev/null 2>&1 || exit 1"]
      interval: 30s
      timeout: 5s
      start_period: 15s
      retries: 3

  # Optional local dependency: Brave Search MCP server (HTTP mode).
  # Start with: docker compose --profile search up -d brave-search
  brave-search:
    image: mcp/brave-search:latest
    container_name: brave-search
    restart: unless-stopped
    profiles: ["search"]
    ports:
      - "18802:8000"
    environment:
      - BRAVE_API_KEY=${BRAVE_API_KEY:?BRAVE_API_KEY is required}
      - BRAVE_MCP_TRANSPORT=http
      - BRAVE_MCP_HOST=0.0.0.0
      - BRAVE_MCP_PORT=8000

  # Optional local dependency: SearXNG metasearch instance.
  # Start with: docker compose --profile search up -d searxng
  searxng:
    image: searxng/searxng:latest
    container_name: searxng
    restart: unless-stopped
    profiles: ["search"]
    ports:
      - "18803:8080"
    environment:
      - BASE_URL=http://localhost:18803/
      - INSTANCE_NAME=Flynn Local SearXNG

volumes:
  flynn-data:
  whisper-models:
