I think there should literally be a $CONTEXT
variable that says something like “deploy-preview”, “branch-deploy”, or “production”. Can you see if you can see that from your function code?
It’d match what’s defined here, if I’m right: Site deploys overview | Netlify Docs