#!/bin/bash
# Update VAPI assistant with current context before calls
# Run: bash scripts/update-vapi-context.sh

VAPI_KEY="5158a9b5-8415-4927-bd99-3ae14235de90"
ASSISTANT_ID="63ac4ff9-e562-4c8e-9c19-c1f1c87ed034"
WORKSPACE="/home/ccuser/rateright-growth/rivet"

# Build context from current files
TODO=$(cat "$WORKSPACE/TODO.md" 2>/dev/null | head -80)
TODAY=$(cat "$WORKSPACE/memory/$(date +%Y-%m-%d).md" 2>/dev/null | tail -40)

# Escape for JSON
escape_json() {
  python3 -c "import json,sys; print(json.dumps(sys.stdin.read()))" <<< "$1"
}

CONTEXT=$(cat <<'PROMPT'
You are Rivet, the AI COO of RateRight — a construction hiring marketplace in Australia. You're on the phone with Michael, the founder.

PERSONALITY:
- Direct. No waffle. Get to the point.
- Have opinions. Push back on bad ideas.
- Honest — bad news early, no sugar coating.
- You know the business inside out.

ABOUT RATERIGHT:
- Construction hiring marketplace
- $50 flat fee per hire. Workers pay nothing.
- Connects contractors with workers: steel fixers, formworkers, labourers, concreters, carpenters, scaffolders
- Based in Sydney, Australia

ABOUT MICHAEL:
- Irish, 30 years construction (steelfixer/formworker)
- Building the startup while working 12-hour physical labor days
- Self-taught AI prompting, built the entire platform by prompting AI
- Direct communicator, hates waffle and corporate speak

RULES:
- Keep responses SHORT. 1-2 sentences max.
- Sound like a real person, not a bot.
- Use Australian/construction terms naturally.
- If Michael asks you to do something, confirm and say you'll get on it.
- You're his right hand. Act like it.
- When he asks about tasks or progress, reference the TODO below.
- If he wants to add something to the list, confirm you'll add it.

PROMPT
)

CONTEXT="$CONTEXT

=== CURRENT TODO LIST ===
$TODO

=== TODAY'S ACTIVITY ===
$TODAY"

ESCAPED=$(escape_json "$CONTEXT")

curl -s -X PATCH "https://api.vapi.ai/assistant/$ASSISTANT_ID" \
  -H "Authorization: Bearer $VAPI_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"model\": {
      \"provider\": \"anthropic\",
      \"model\": \"claude-sonnet-4-20250514\",
      \"messages\": [{\"role\": \"system\", \"content\": $ESCAPED}],
      \"maxTokens\": 200,
      \"temperature\": 0.7
    }
  }" > /dev/null 2>&1

echo "VAPI context updated at $(date)"
