#!/usr/bin/env bash
set -euo pipefail

cd "$(dirname "$0")/../.."

PYTHON_BIN="${PYTHON_BIN:-python3}"

MAIN_MODEL_PROVIDER="anthropic_bedrock"
MAIN_MODEL="global.anthropic.claude-opus-4-5-20251101-v1:0"
MAIN_URL=""
MAIN_API_KEY=""

GROUNDING_PROVIDER="qwen"
GROUNDING_MODEL="gui-plus-2026-02-26"
GROUNDING_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
GROUNDING_API_KEY="${DASHSCOPE_API_KEY}"

SEARCHER_PROVIDER="gemini"
SEARCHER_MODEL="gemini-3.1-pro-preview"
SEARCHER_API_KEY="${GEMINI_API_KEY}"

SEARCHER_PROVIDER="gemini"
SEARCHER_MODEL="gemini-3.1-pro-preview"
SEARCHER_API_KEY=""

mkdir -p logs

TIMESTAMP="$(date +%Y%m%d_%H%M%S)"
LOG_FILE="${LOG_FILE:-logs/run_vlaa_gui_claude_${TIMESTAMP}.log}"

echo "Logging to ${LOG_FILE}"

"${PYTHON_BIN}" scripts/python/run_multienv_vlaa.py \
  --provider_name "${PROVIDER_NAME:-aws}" \
  --region "${REGION:-${AWS_REGION:-us-east-1}}" \
  --client_password "${CLIENT_PASSWORD:-${OSWORLD_CLIENT_PASSWORD:-osworld-public-evaluation}}" \
  --headless \
  --result_dir "${RESULT_DIR:-./results-vlaa-gui}" \
  --model_dir_name "${MODEL_DIR_NAME:-claude}" \
  --test_all_meta_path "${TEST_META_PATH:-evaluation_examples/test_all.json}" \
  --domain "${DOMAIN:-all}" \
  --max_steps "${MAX_STEPS:-100}" \
  --num_envs "${NUM_ENVS:-36}" \
  --sleep_after_execution "${SLEEP_AFTER_EXECUTION:-3}" \
  --max_image_in_trajectory 8 \
  --model_provider "${MAIN_MODEL_PROVIDER}" \
  --model "${MAIN_MODEL}" \
  --model_url "${MAIN_URL}" \
  --model_api_key "${MAIN_API_KEY}" \
  --model_thinking \
  --model_temperature 1.0 \
  --grounding_model_type "unified" \
  --grounding_model_provider "${GROUNDING_PROVIDER}" \
  --grounding_model "${GROUNDING_MODEL}" \
  --grounding_model_url "${GROUNDING_URL}" \
  --grounding_model_api_key "${GROUNDING_API_KEY}" \
  --grounding_width 1000 \
  --grounding_height 1000 \
  --coding_model_provider "${MAIN_MODEL_PROVIDER}" \
  --coding_model "${MAIN_MODEL}" \
  --coding_model_url "${MAIN_URL}" \
  --coding_model_api_key "${MAIN_API_KEY}" \
  --coding_model_thinking \
  --coding_model_thinking_level "high" \
  --coding_model_temperature 1.0 \
  --embedding_engine_type "openai" \
  --observation_type "screenshot" \
  --with_reflection \
  --search_engine "search_agent" \
  --memory_type "null" \
  --searcher_type "llm" \
  --searcher_provider "${SEARCHER_PROVIDER}" \
  --searcher_model "${SEARCHER_MODEL}" \
  --searcher_api_key "${SEARCHER_API_KEY}" \
  --searcher_budget 5 \
  --searcher_temperature 1.0 \
  --searcher_reasoning_effort "high" \
  --action_space "pyautogui_coding" \
  --use_verifier \
  --enable_gate \
  --loop_detection \
  --feasibility_check \
  2>&1 | tee "${LOG_FILE}"
