#!/usr/bin/env bash
# Quickstart step 8 — read a user's embedding and score from the serving API.
set -euo pipefail

: "${TESSERA_API_BASE:?e.g. https://api.staging.tessera.zone/v1}"
: "${TESSERA_API_KEY:?your tsk_test_… key}"

STATE="$(curl -sS "$TESSERA_API_BASE/slots/quickstart/entities/user/u_00001/state" \
  -H "Authorization: Bearer $TESSERA_API_KEY")"

echo "$STATE" | python3 -m json.tool

# Every scored response is auditable: the embedding, the per-label scores,
# and the freshness block naming the exact model fingerprint and the last
# event the state incorporates.
printf '%s' "$STATE" | python3 -c '
import json, sys
state = json.load(sys.stdin)
freshness = state["freshness"]
print("embedding_dimension:", len(state["embedding"]))
print("score repeat_purchase_30d present:", "repeat_purchase_30d" in state["scores"])
print("model_fingerprint:", freshness["model_fingerprint"])
print("event_cursor timestamp:", freshness["event_cursor"]["timestamp"])
'
