# Task 012 — AI Reply Classification

## Objective

Classify inbound inbox replies using a flexible AI provider layer and persist results for future Lead creation.

## Status

**Done** (June 2026)

## Acceptance criteria

- [x] `npm run build` succeeds
- [x] `npm run lint` succeeds
- [x] `AI_PROVIDER=fallback` works without API keys
- [x] `AI_PROVIDER=openai` works when `OPENAI_API_KEY` is set
- [x] Missing OpenAI key falls back safely
- [x] `GET /api/ai/status` works
- [x] `POST /api/ai/classify-preview` works
- [x] User can classify an inbox reply from UI
- [x] `AiClassification` record created
- [x] `EmailReply.status` updates (`classified` / `spam` / `ignored`)
- [x] Inbox detail shows classification
- [x] Bulk classify with limit works
- [x] No Leads created
- [x] Documentation and changelog updated

## Implementation summary

- `src/server/ai/**` — provider interface, factory, fallback + OpenAI + placeholders
- `src/server/services/ai-classification.service.ts`
- `src/app/api/ai/**`
- `src/components/inbox/ai-classification-panel.tsx`
- `src/app/ai/status/page.tsx`

## Next

Task 013 — Leads & Pipeline: create/update leads from classified replies.
