# Source me: finds the running engine and defines small helpers.
export BASE=$(jq -r .url ~/.lelu/engine.json)
export KEY=$(cat ~/.lelu/engine.key)
# authz '<json body>'  -> POST /v1/agent/authorize, print the fields that matter
authz() {
  curl -sS -H 'Content-Type: application/json' -H "Authorization: Bearer $KEY" \
    -X POST "$BASE/v1/agent/authorize" --data "$1" \
  | jq -c '{allowed, review: .requires_human_review, compute, review_id, confidence_used, provider_signal_present, reason}
           | with_entries(select(.value != null))'
}
# api METHOD PATH [json body] [extra curl args...]
api() {
  m="$1"; p="$2"; b="${3:-}"; shift; shift; [ $# -gt 0 ] && shift
  curl -sS -w '\nHTTP %{http_code}\n' -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $KEY" -X "$m" "$BASE$p" ${b:+--data "$b"} "$@"
}
