#!/usr/bin/env bash
# Launch the Bluera Knowledge admin web UI.
# Starts the HTTP server with auto port detection and opens the browser.

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PLUGIN_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"

# Use the built dist
SERVER="$PLUGIN_ROOT/dist/index.js"

if [ ! -f "$SERVER" ]; then
  echo "Error: Built server not found at $SERVER"
  echo "Run 'bun run build' or 'npm run build' first."
  exit 1
fi

echo "Starting Bluera Knowledge admin UI..."
exec node "$SERVER" serve --open
