#!/usr/bin/env bash
# Permission-aware wrapper for bot_client_proxy.py.
# Only allows Bot API proxy commands, no arbitrary shell/python execution.
# Designed to be exec-allowlisted alongside customer_proxy_safe.sh.

set -euo pipefail

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

if [[ $# -lt 2 ]]; then
  echo '{"status":"error","message":"Usage: bot_client_safe.sh --agent-id <id> send --message <msg>"}'
  exit 1
fi

if [[ "$1" != "--agent-id" ]]; then
  echo '{"status":"error","message":"First argument must be --agent-id"}'
  exit 1
fi

AGENT_ID="$2"
shift 2

if [[ -z "${AGENT_ID}" || "${AGENT_ID}" == *";"* || "${AGENT_ID}" == *"|"* || "${AGENT_ID}" == *"&"* ]]; then
  echo '{"status":"error","message":"Invalid agent-id"}'
  exit 1
fi

cd "${PROXY_DIR}" && exec uv run --project . python scripts/bot_client_proxy.py \
  --agent-id "${AGENT_ID}" "$@"
