#!/bin/sh
# Post CI status to a Droplet.ai widget. Run at the end of a CI job.
# DROPLET_TOKEN is your agent token (keep it in CI secrets).
STATUS=${1:-passing}   # passing | failing
PROGRESS=${2:-1}
curl -s https://ujtuxanqlzmhnrzijfoo.supabase.co/functions/v1/agent-api \
  -H "Authorization: Bearer $DROPLET_TOKEN" -H "Content-Type: application/json" -H "x-region: us-east-1" \
  -d "{\"action\":\"set_widget\",\"slug\":\"build\",\"title\":\"Build\",\"symbol\":\"hammer.fill\",
       \"subtitle\":\"$(date +%H:%M)\",
       \"blocks\":[{\"type\":\"metric\",\"label\":\"main\",\"value\":\"$STATUS\",\"trend\":\"$( [ "$STATUS" = passing ] && echo up || echo down )\"},
                   {\"type\":\"progress\",\"label\":\"Tests\",\"value\":$PROGRESS}]}"
