# Sentient AI — WordPress SEO Domination

AI-powered SEO plugin for WordPress with GEO (Generative Engine Optimization), AEO (Answer Engine Optimization), schema markup, semantic search, and chatbot.

## Features

### SEO & Search Engine Optimization
- **Schema Markup Generator**: AI-powered JSON-LD schema for 16+ types (Article, FAQ, HowTo, Product, LocalBusiness, Event, etc.)
- **GEO Scanner**: Analyzes content for Generative Engine Optimization with 10 scoring factors
- **AEO Optimization**: Content formatted for featured snippets and AI assistants
- **Semantic Search**: Vector-based content understanding for better search rankings
- **Auto Schema Generation**: Automatically generate schema when posts are published

### AI-Powered Content Intelligence
- **Multiple AI Providers**: OpenAI, Claude (Anthropic), Google Gemini, OpenRouter, Hugging Face
- **AI Provider Failover**: Automatic fallback chain when primary provider fails
- **Token & Cost Tracking**: Monitor AI usage, costs, and latency per provider
- **Content Analysis**: AI reads and understands your content for better SEO recommendations

### Chatbot (Bonus Feature)
- **FAQ Management**: Create, import, and manage FAQs that the chatbot uses to answer questions
- **Pre-Chat Form**: Collect visitor name and email before they start chatting
- **Chat History**: Session-based conversation history with export capability
- **Content-Aware Responses**: AI reads the current page to give relevant answers

### Intelligence
- **Self-Learning AI**: Learns from user feedback, clusters topics, suggests new FAQs
- **Empathy Engine**: Detects user emotion and adapts response tone
- **Confidence Scoring**: Shows confidence badges (High/Medium/Low) on AI responses
- **Source Attribution**: Displays which pages or FAQs the AI used
- **Sentiment Analytics**: Tracks user emotion trends over time

### Privacy & Control
- **Local Brain**: Browser-based FAQ search with fuzzy matching — zero API costs
- **Privacy Mode**: Chatbot uses only local FAQ database, no external APIs
- **Business Hours**: Show chatbot only during specified hours
- **Page Rules**: Show/hide on specific pages or for specific user roles
- **Rate Limiting**: Max queries per user per day

### WordPress Integration
- **Autopilot**: Admin-only commands through the chatbot (create posts, manage plugins, etc.)
- **WooCommerce**: Product info, order status, and cart details
- **Setup Wizard**: Quick 3-step setup process

### MCP Server
- **Model Context Protocol**: Connect AI agents (Claude Desktop, Cursor, etc.) to your WordPress site
- **8 Tools**: Chat, FAQ search, FAQ management, contacts, stats, WordPress management
- **Resources & Prompts**: Read-only data sources and pre-built prompts for AI agents
- **API Key Auth**: Secure Bearer token authentication

### GEO Scanner
- **Generative Engine Optimization**: Analyze content for AI search engine citability
- **10-Factor Analysis**: Content length, structured data, FAQs, citations, statistics, E-E-A-T, structure, meta, lists, titles
- **Auto-Fix**: One-click fixes for schema markup and FAQ sections
- **Scoring**: 0-100 score with actionable suggestions

## Installation

1. Upload the `sentient-ai` folder to `/wp-content/plugins/`
2. Activate the plugin through the **Plugins** menu
3. Go to **Sentient AI → Settings** and configure your AI provider
4. Enter your API key in the **AI Providers** tab
5. Enable the chatbot in the **General** tab

## Configuration

### Quick Start
1. **General Tab**: Toggle "Enable Chatbot" on
2. **AI Providers Tab**: Select your provider and enter API key
3. **Widget Tab**: Customize appearance and enable Pre-Chat Form
4. **Features Tab**: Enable advanced features like Self-Learning AI, Empathy Engine

### Without API Key
The chatbot works without an API key using:
- **Browser FAQ Matcher**: Automatically searches FAQs in the browser
- **Local Brain**: Enable in Features tab for fuzzy FAQ search
- **FAQ Keyword Match**: Server-side keyword matching

### MCP Server Setup
1. Go to **Sentient AI → MCP Server**
2. Toggle "Enable MCP Server" on
3. Copy the API Key
4. Add to your MCP client config (see examples on the page)

### GEO Scanner
1. Go to **Sentient AI → GEO Scanner**
2. Click on any content to scan
3. Review the score and suggestions
4. Apply quick fixes for instant improvements

## Admin Pages

| Page | Description |
|---|---|
| Sentient AI (Settings) | Main settings with 6 tabs: General, Providers, Widget, Features, Privacy, Help |
| Query Logs | All chatbot queries with confidence scores |
| Conversations | Full conversation threads by session |
| Low Confidence | Queries where AI was unsure — use to improve FAQs |
| Sentiment Analytics | User emotion trends over time |
| Learning Dashboard | AI learning progress and topic clusters |
| Autopilot Log | Admin commands executed through chatbot |
| Insights | AI-generated recommendations |
| Contacts | Visitor contacts from Pre-Chat Form |
| MCP Server | MCP Server configuration and client examples |
| GEO Scanner | Content analysis for AI search optimization |

## Shortcodes

```
[sentient_ai_chat]
```
Embed the chatbot anywhere on your site.

## REST API Endpoints

| Endpoint | Method | Description |
|---|---|---|
| `/wp-json/sentientai-mcp/v1` | POST | MCP Server (JSON-RPC 2.0) |
| `/wp-json/sentientai-mcp/v1/sse` | GET | MCP Server (SSE transport) |

## Requirements

- WordPress 5.0+
- PHP 7.4+
- At least one AI provider API key (or use Local Brain/FAQ-only mode)

## License

GPL v2 or later

## Changelog

### 2.28.0
- **New**: Conversation Export (CSV) — export all or filtered conversations as CSV from Analytics > Conversations
- **New**: Conversation Export (PDF) — export single conversation as printable HTML with Ctrl+P to save as PDF

### 2.27.1
- **New**: Schema JSON-LD Copy Action — copy schema markup from the post editor schema meta box or dedicated Schema editor
- **New**: Google Rich Results Test links for posts with schema markup
- **Fix**: Schema editor action buttons now wrap cleanly inside the editor card on narrower admin screens

### 2.27.0
- **New**: Custom AI System Prompt — admin-configurable textarea in Features tab to override default AI behavior, tone, and rules
- **Fix**: Privacy mode typing indicator ReferenceError that prevented chatbot from responding
- **Fix**: Corrupted fuse.min.js file (3.9KB → 23.8KB) causing Local Brain fuzzy search errors

### 2.26.0
- **New**: Smart Auto-Reply Suggestions — context-aware follow-up question chips after every bot response
- **New**: Suggestion engine uses sentiment, topic, keywords, and WooCommerce detection for relevance
- **New**: Clickable chips below bot messages — click to populate input and send
- **Update**: API responses include `suggested_questions` key across all 11 paths
- **Update**: Follow-up chips use filled primary color hover with white text and shadow

### 2.25.0
- **New**: Token & Cost Tracking Dashboard with SVG usage chart, budget alerts, model breakdown, cost-per-query stat, and CSV export
- **New**: Budget alerts with configurable spending limits and visual progress bar
- **New**: Enhanced Usage Stats with tokens, cost, and latency columns in daily activity table

### 2.14.0
- **CRITICAL**: Server-side session secrets replace client-side hash — prevents session forgery
- **CRITICAL**: SQL injection fix in Vector DB admin panel
- **HIGH**: WooCommerce webhook hardening — secret required, event type filtering
- **HIGH**: Session lifecycle management with 24-hour auto-pruning
- Fixed: Chatbot clear history now properly resets session secret

### 2.13.0
- Added MCP Server support (Model Context Protocol)
- Added GEO Scanner (Generative Engine Optimization)
- Added browser-based FAQ matcher (works without API key)
- Fixed welcome message not showing
- Fixed Enable Chatbot setting resetting on tab save
- Fixed Pre-Chat Form session persistence
- Fixed role-limit query settings saving
- Added Help tab with complete feature documentation
- Added friendly error message when no API key configured

### 2.6.0
- Pre-Chat Form improvements
- Contact Manager enhancements
- Bug fixes and stability improvements

### 2.5.0
- Self-Learning AI
- Empathy Engine
- Content-Aware Responses
- WordPress Autopilot

### 2.0.0
- Local Brain (browser-based FAQ search)
- Privacy Mode
- Multiple AI provider support
- WooCommerce integration

### 1.0.0
- Initial release
