#!/bin/sh
set -eu

# Diagnostic direct-API example. Run it only from a trusted server-side shell.
# It makes one request and leaves retry policy to the calling application.
if [ -z "${TYPESAFE_API_KEY:-}" ]; then
  printf '%s\n' 'TYPESAFE_API_KEY is required; keep it server-side and do not print it.' >&2
  exit 2
fi

curl --fail-with-body --silent --show-error --include \
  --connect-timeout 5 \
  --max-time 20 \
  --request POST https://api.typesafe.ai/v1/systemone \
  --header "Authorization: Bearer $TYPESAFE_API_KEY" \
  --header 'Content-Type: application/json' \
  --write-out '\nHTTP %{http_code}\n' \
  --data-binary @- <<'JSON'
{
  "model": "jev-latest",
  "state": {
    "message": "Checkout returns HTTP 500 after payment."
  },
  "questions": {
    "route": {
      "type": "choice",
      "instructions": "Which team should handle this request?",
      "criteria": {
        "billing": "Charges, invoices, or subscriptions",
        "technical": "Bugs, APIs, or integrations",
        "human": "Ambiguous or sensitive cases"
      }
    }
  }
}
JSON
