Skip to content

v2.0.0 — Phase 2: Claude AI Agent + Weekly Reports + Cron Automation

Choose a tag to compare

@deepan-mehta-analytics deepan-mehta-analytics released this 31 May 04:40

🏠 StayOps — v2.0.0

Phase 2 ships the AI agent layer: Claude tool-calling reconciliation analysis, weekly Slack reports, turnover auto-generation, and the full server-to-client UI wiring.


What's included

Schema (Task 1)

Column Type Purpose
accepted_by text Operator who clicked Accept — audit trail
accepted_at timestamp When Accept was clicked
ai_confidence integer 0–100 Claude's probability score stored at resolve time
user_feedback varchar(20) "correct" / "wrong" / null — Phase 3 ML training label

AI Agent (lib/ai-agent.ts) (Task 2)

  • RECONCILIATION_TOOLS — 3 tools: get_booking_details, get_property_info, propose_resolution (required: action, confidence, reasoning_summary)
  • CHANNEL_PRIORITY["airbnb", "direct", "booking_com", "vrbo"]
  • Full multi-turn agentic loop via streamAnalysis() — emits NDJSON events: text, tool_call_start, proposal, done
  • resolveFlag() — writes status, resolution, resolvedAt, acceptedBy, acceptedAt

Weekly Report (lib/weekly-report.ts) (Task 3)

  • getCurrentIsoWeek() — ISO 8601 Thursday-anchoring, returns YYYY-Www
  • formatWeeklyReport() — pure Markdown formatter
  • buildWeeklyReport() — assembles live DB stats + formats report

API Routes (Task 4)

Route Method Purpose
/api/ai/analyze POST Stream analysis from Claude agent
/api/ai/resolve POST Accept a proposed resolution
/api/ai/feedback POST Record 👍/👎 feedback without resolving
/api/cron/weekly-report POST Generate + deliver weekly Markdown report
/api/cron/generate-turnovers POST Idempotent nightly turnover task creation

ConflictSlideOver component (Task 5)

  • 3 states: idle (conflict detail), analysing (streaming tokens), resolved (confirmation)
  • Glassmorphism panel: rgba(255,255,255,0.92) + backdrop-filter: blur(16px)
  • Feature-flagged: NEXT_PUBLIC_ENABLE_AI_AGENT=true gates the Analyze button
  • Confidence badge colours: ≥90 violet · ≥70 amber · <70 red

ReconciliationClient + page refactor (Task 6)

  • "use client" boundary with selectedFlag state and violet row highlight
  • key={selectedFlag.id} forces slide-over remount on row switch
  • Server component serialises Date → ISO string before passing to client

Vercel Cron (Task 7)

Cron Schedule
/api/cron/weekly-report Mondays 08:00 UTC
/api/cron/generate-turnovers Daily midnight UTC

Tests (Task 8)

Suite Tests
lib/reconciliation.test.ts 8
lib/ai-agent.test.ts 8
lib/weekly-report.test.ts 7
Total 23

Roadmap

  • v3.0.0 — Phase 3 growth surface (direct-booking landing page + PostHog funnel + lead capture + AI listing copy)