|
| 1 | +#!/bin/sh |
| 2 | +set -e |
| 3 | + |
| 4 | +# Wait for broker to be healthy |
| 5 | +echo "Waiting for broker at ${AGENTWRIT_BROKER_URL}..." |
| 6 | +until curl -sf "${AGENTWRIT_BROKER_URL}/v1/health" > /dev/null 2>&1; do |
| 7 | + sleep 1 |
| 8 | +done |
| 9 | +echo "Broker is ready." |
| 10 | + |
| 11 | +# Auto-register app if no client credentials provided |
| 12 | +if [ -z "${AGENTWRIT_CLIENT_ID}" ] || [ -z "${AGENTWRIT_CLIENT_SECRET}" ]; then |
| 13 | + echo "No client credentials — registering app with broker..." |
| 14 | + |
| 15 | + if [ -z "${AGENTWRIT_ADMIN_SECRET}" ]; then |
| 16 | + echo "ERROR: AGENTWRIT_ADMIN_SECRET required for auto-registration" |
| 17 | + exit 1 |
| 18 | + fi |
| 19 | + |
| 20 | + # Authenticate as admin |
| 21 | + ADMIN_TOKEN=$(curl -sf -X POST "${AGENTWRIT_BROKER_URL}/v1/admin/auth" \ |
| 22 | + -H "Content-Type: application/json" \ |
| 23 | + -d "{\"secret\":\"${AGENTWRIT_ADMIN_SECRET}\"}" \ |
| 24 | + | python3 -c "import sys,json; print(json.load(sys.stdin)['access_token'])") |
| 25 | + |
| 26 | + # Register the demo app |
| 27 | + APP_JSON=$(curl -sf -X POST "${AGENTWRIT_BROKER_URL}/v1/admin/apps" \ |
| 28 | + -H "Content-Type: application/json" \ |
| 29 | + -H "Authorization: Bearer ${ADMIN_TOKEN}" \ |
| 30 | + -d '{ |
| 31 | + "name": "medassist-demo", |
| 32 | + "scopes": [ |
| 33 | + "read:records:*", "write:records:*", "read:labs:*", |
| 34 | + "write:prescriptions:*", "read:formulary:*", |
| 35 | + "read:billing:*", "write:billing:*", "read:insurance:*" |
| 36 | + ], |
| 37 | + "token_ttl": 1800 |
| 38 | + }') |
| 39 | + |
| 40 | + export AGENTWRIT_CLIENT_ID=$(echo "${APP_JSON}" | python3 -c "import sys,json; print(json.load(sys.stdin)['client_id'])") |
| 41 | + export AGENTWRIT_CLIENT_SECRET=$(echo "${APP_JSON}" | python3 -c "import sys,json; print(json.load(sys.stdin)['client_secret'])") |
| 42 | + |
| 43 | + echo "App registered: ${AGENTWRIT_CLIENT_ID}" |
| 44 | +fi |
| 45 | + |
| 46 | +echo "Starting MedAssist AI on port 5000..." |
| 47 | +exec uv run uvicorn demo.app:app --host 0.0.0.0 --port 5000 |
0 commit comments