#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

CDP_PORT="${SOLACE_CDP_PORT:-9888}"
CDP_ARGS=()
if [ "${CDP_PORT}" != "0" ]; then
  CDP_ARGS=("--remote-debugging-address=127.0.0.1" "--remote-debugging-port=${CDP_PORT}")
fi

# Open the APEX (solaceagi.com) — not www. Auth cookies are set on the
# apex; the sidebar fetches /api/v1/oauth3/me/status against the apex.
# If we open www, sign-in cookies land on the wrong host and the
# sidebar shows "Not signed in" even when the operator is signed in
# (verified live 2026-05-18 build90; comment at side_panel_helper.cc
# kDefaultBackend explains the cookie-scope rationale).
STARTUP_ARGS=()
if [ "$#" -eq 0 ]; then
  STARTUP_ARGS=("https://solaceagi.com/")
fi

exec "${SCRIPT_DIR}/solace" \
  --homepage=https://solaceagi.com \
  "${CDP_ARGS[@]}" \
  "${STARTUP_ARGS[@]}" \
  "$@"
