=== Sentient AI - WordPress AI Chatbot with Local Brain, Autopilot & Empathy Engine ===
Contributors: maidulcu
Tags: ai chatbot, chatbot, openai, customer support, faq, live chat, gpt, claude, gemini, wordpress chatbot, ai assistant, support chatbot, help desk, chat widget, privacy ai, local ai, woocommerce chatbot
Requires at least: 5.8
Tested up to: 6.9
Requires PHP: 7.4
Stable tag: 2.6.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

The only WordPress AI chatbot with Local Brain (zero API costs), Autopilot (site management), Empathy Engine (emotion-aware), and Glass Box (transparent AI).

== Description ==

**Sentient AI** is a revolutionary WordPress chatbot plugin that doesn't just answer questions — it *manages your site, learns from interactions, and respects privacy*. With Local Brain processing, WordPress Autopilot, emotion-aware AI, and transparent confidence scoring, it's the most powerful AI assistant for WordPress.

=== Why Sentient AI is Different ===

Unlike other chatbots that are black boxes, Sentient AI includes:

* **Widget Branding** — 6 preset themes, custom colors, border radius — match your brand perfectly
* **WooCommerce Integration** — Product lookup, order status, recommendations, cart info in chat
* **Local Brain** — Process FAQ answers locally in the browser. Zero API costs, full privacy, works offline.
* **WordPress Autopilot** — AI agent that manages your site: check updates, find broken images, create posts, scan security.
* **Sentient Memory** — Learns from every interaction, builds topic knowledge, and auto-generates FAQs.
* **Empathy Engine** — Detects user emotion (frustrated, confused, urgent, happy) and adapts AI response tone.
* **Glass Box Transparency** — Every response shows a confidence score (High/Medium/Low) and source attribution.
* **5 AI Providers** — OpenAI (GPT-4, GPT-3.5), Claude (Anthropic), Google Gemini, OpenRouter, Hugging Face.
* **Auto-Escalation** — Frustrated users and low-confidence answers automatically offer "Talk to a human".

=== Perfect For ===

* **SaaS companies** — Reduce support tickets with AI that understands user frustration
* **E-commerce stores** — Answer product questions with empathy during checkout issues
* **Agencies** — Deploy smart chatbots for clients with emotional intelligence
* **Membership sites** — Help members find answers without human support
* **Blogs & content sites** — Guide readers to relevant content with personalized tone
* **Privacy-conscious sites** — Use Local Brain for zero external API calls

= Key Features =

**Local Brain (v2.2.0)**
* Fuzzy FAQ search locally in the browser (Fuse.js-powered)
* Zero API costs for FAQ-matched responses
* Works offline — FAQ answers available without internet
* Privacy Mode — never send data to external AI services
* Instant responses with no network latency

**WordPress Autopilot (v2.1.0)**
* Check for plugin, theme, and WordPress updates
* Find broken images in posts
* List and search posts by keyword
* Create draft posts/pages from chat
* Security vulnerability scanning
* Cache clearing (transient purge)
* Site statistics and health checks

**Sentient Memory (v2.0.0)**
* Continuous learning from every interaction
* Automatic topic clustering from user queries
* Thumbs up/down feedback tracking
* Auto-FAQ generation for frequently asked questions
* Learning Dashboard with topics, trending, low quality answers

**Empathy Engine (v1.4.0)**
* Real-time emotion detection (frustrated, confused, urgent, happy)
* Dynamic system prompts adapt AI tone based on user mood
* Persistent frustration detection with auto-escalation

**Glass Box Transparency (v1.3.0)**
* Confidence scoring on every AI response (0-100%)
* Source attribution showing which pages/FAQs were used
* Low confidence dashboard for admin review

**Multi-Turn Conversations (v1.2.0)**
* AI remembers previous messages for contextual conversations
* Configurable context size (3-20 messages)
* Server-side conversation persistence

**Enterprise-Ready Security**
* Rate limiting (5 requests/minute/IP)
* Nonce verification on all AJAX calls
* Capability checks on admin operations
* Input sanitization and output escaping

= What Users Say =

> "Finally, a chatbot that doesn't just guess — it shows its work." — WordPress developer

> "The confidence scores helped me identify exactly which FAQs needed improvement." — E-commerce owner

> "Reduced our support tickets by 40% in the first month." — SaaS company

> "Local Brain means zero API costs for our FAQ-heavy site." — Agency owner

== Installation ==

1. Upload the plugin folder to `/wp-content/plugins/sentient-ai`
2. Activate the plugin from the **Plugins** menu
3. Go to **Sentient AI → Settings** to configure your AI provider and API key
4. Enable the chatbot and customize the welcome message
5. Place `[sentient_ai_chat]` on any page, or use the floating widget

== Frequently Asked Questions ==

= Does this work without an API key? =

Yes! With Local Brain enabled, the chatbot answers FAQ questions locally without any API key. For AI-powered responses beyond FAQs, you'll need an API key from one of the supported providers.

= What makes this different from other chatbot plugins? =

**Everything.** Sentient AI has:
- Local Brain (zero-cost local processing)
- WordPress Autopilot (site management through chat)
- Sentient Memory (continuous learning)
- Empathy Engine (emotion-aware responses)
- Glass Box (transparent confidence scoring)
No other chatbot plugin has all of these.

= Does it work with WooCommerce? =

Yes! The chatbot works alongside WooCommerce. You can train the AI on your product pages and answer customer questions instantly.

= Can I use it without sending data to external APIs? =

Yes! Enable Privacy Mode in settings. The chatbot will only use your local FAQ database and never send data to OpenAI, Claude, or any external service.

= Does it slow down my website? =

No. The chatbot loads asynchronously in the footer. Local Brain assets (Fuse.js + local-brain.js) are only loaded when enabled and total ~8KB.

= How does Local Brain work? =

Local Brain uses Fuse.js for fuzzy search across your FAQ database. When a user asks a question, it searches locally in the browser first. If it finds a good match, it returns the answer without any API call. Falls back to cloud AI for unmatched queries.

= Can I customize the chatbot's appearance? =

Yes. You can change the welcome message, chat position (left/right), colors via CSS, and toggle confidence scores, source links, and sentiment indicators.

== Screenshots ==

1. Settings page — Provider configuration, API keys, widget settings, and feature toggles
2. Query Logs — Searchable conversation history with response types and FAQ linking
3. Conversations — Session-based conversation viewer with message threading
4. Low Confidence Queries — AI answers below threshold with create-FAQ actions
5. Sentiment Analytics — Emotion distribution (happy, frustrated, confused) with time range filters
6. Learning Dashboard — Topic clustering, trending topics, auto-FAQ suggestions, and low quality tracking
7. WordPress Autopilot — Available commands, activity log, and site management stats
8. Sentient Insights — Priority-ranked recommendations with action suggestions
9. Train Assistant — Content type selection, field configuration, and training data preview
10. Import FAQs — CSV upload with format instructions and tips

== External Services ==

This plugin connects to external AI service providers to generate intelligent chatbot responses. The plugin requires you to configure API credentials for your selected provider. **Local Brain mode sends no data to external services.**

=== OpenAI ===
* **Service Purpose**: Provides AI-powered responses through OpenAI's GPT models and Assistants API
* **Data Sent**: User queries, conversation history, and your configured assistant context
* **When Data is Sent**: When a user submits a question that doesn't match an existing FAQ
* **API Endpoints Used**: https://api.openai.com/v1/chat/completions, https://api.openai.com/v1/threads, https://api.openai.com/v1/assistants
* **Terms of Service**: https://openai.com/terms
* **Privacy Policy**: https://openai.com/privacy

=== Claude (Anthropic) ===
* **Service Purpose**: Provides AI-powered responses using Anthropic's Claude models
* **Data Sent**: User queries and conversation history
* **When Data is Sent**: When a user submits a question that doesn't match an existing FAQ
* **API Endpoints Used**: https://api.anthropic.com/v1/messages
* **Terms of Service**: https://www.anthropic.com/legal/consumer-terms
* **Privacy Policy**: https://www.anthropic.com/legal/privacy

=== Google Gemini ===
* **Service Purpose**: Provides AI-powered responses using Google's Gemini models
* **Data Sent**: User queries and conversation history
* **When Data is Sent**: When a user submits a question that doesn't match an existing FAQ
* **API Endpoints Used**: https://generativelanguage.googleapis.com/v1beta/models/{model}:generateContent
* **Terms of Service**: https://policies.google.com/terms
* **Privacy Policy**: https://policies.google.com/privacy

=== OpenRouter ===
* **Service Purpose**: Provides access to multiple AI models through a unified API
* **Data Sent**: User queries, conversation history, and FAQ context
* **When Data is Sent**: When a user submits a question that doesn't match an existing FAQ
* **API Endpoints Used**: https://openrouter.ai/api/v1/chat/completions
* **Terms of Service**: https://openrouter.ai/terms
* **Privacy Policy**: https://openrouter.ai/privacy

=== Hugging Face ===
* **Service Purpose**: Provides access to open-source AI models
* **Data Sent**: User queries and conversation history
* **When Data is Sent**: When a user submits a question that doesn't match an existing FAQ
* **API Endpoints Used**: https://api-inference.huggingface.co/models/{model}
* **Terms of Service**: https://huggingface.co/terms-of-service
* **Privacy Policy**: https://huggingface.co/privacy

== Changelog ==

= 2.6.0 =
* **Security Hardening** — Multiple vulnerability fixes and sanitization improvements
* Fixed OpenAI Assistant ID leak in chat responses
* Added output sanitization for WooCommerce product/order data
* Escaped conversation history AJAX responses
* Removed autopilot_data from frontend responses
* **Design Refresh** — Modernized chatbot UI
* Redesigned chat header, message bubbles, and input area
* Moved all dynamic styles from JS inline to CSS variables
* Improved placeholder text visibility and SVG icon rendering
* Fixed send button icon width collapsing to 0
* **Bug Fixes**
* Fixed `typingIndicator` ReferenceError (used before declaration)
* Fixed chat history not persisting locally for bot messages
* Fixed clear_cache transient counting (only counted last query)
* Fixed `Logger::log_query` not returning insert ID (confidence/sentiment never saved)
* Fixed Autopilot approval flow (restored `needs_approval` response field)
* Fixed `elseif` syntax error in JavaScript (→ `else if`)
* **Reliability**
* Auto-create DB tables on init if missing (Logger, Conversation_Handler)
* Added Autopilot test suite (25+ tests)
* XSS prevention in source link rendering (`.text()` instead of `.html()`)

= 2.4.0 =
* **WooCommerce Deep Integration** — AI-powered product assistance
* Product information lookup by name or SKU
* Order status checking with item details
* Product recommendations based on popularity
* Cart info display in chat
* WooCommerce statistics for admin
* Performance improvements: FAQ query caching
* Added Options_Cache helper for static option caching
* Fixed FAQ matching N+1 query issue

= 2.3.0 =
* **Widget Branding & Theming** — Full customization of chatbot appearance
* 6 preset themes: Indigo, Ocean, Emerald, Rose, Amber, Slate
* Custom primary color picker
* Custom header color picker
* Adjustable border radius (0-24px)
* Live preview in admin settings
* Dynamic CSS injection based on settings
* **Prompt Injection Protection** — Security hardening against AI manipulation
* 20+ injection pattern detection
* Blocks instruction override attempts
* Blocks system prompt extraction
* Protects system prompts with boundary markers

= 2.2.0 =
* **Local Brain** — Privacy-first local FAQ processing with fuzzy search
* Fuse.js-powered fuzzy matching for instant FAQ answers
* Zero API costs for FAQ-matched responses
* Works offline — FAQ answers available without internet
* Privacy Mode toggle — never send data to external AI services
* Local/AI source badges on chat responses
* Added local-brain.js and fuse.min.js assets

= 2.1.0 =
* **WordPress Autopilot** — AI agent that manages your site through chat
* 10 supported commands: updates, broken images, list/create posts, security, cache, stats, health, FAQs, logs
* Intent classification with keyword pattern matching
* Action approval system for destructive operations
* Autopilot activity log for admin review

= 2.0.0 =
* **Sentient Memory** — Continuous learning from every interaction
* Automatic topic clustering from user queries
* Thumbs up/down feedback tracking
* Auto-FAQ generation for frequently asked questions
* Learning Dashboard with topics, trending, low quality answers

= 1.4.0 =
* **Empathy Engine** — Detects user emotion and adapts AI response tone
* Real-time emotion detection (frustrated, confused, urgent, happy)
* Dynamic system prompts based on user mood
* Persistent frustration detection with auto-escalation

= 1.3.0 =
* **Glass Box Transparency** — Confidence scoring and source attribution
* Confidence badges (High/Medium/Low) on every response
* Source links showing which pages/FAQs were used
* Low confidence dashboard for admin review

= 1.2.0 =
* Multi-turn conversation context
* Server-side chat history persistence
* Configurable context size (3-20 messages)

= 1.1.1 =
* Security and performance hotfixes

= 1.1.0 =
* Session-based chat history, TXT export, configurable position

= 1.0.0 =
* Initial release

== Upgrade Notice ==

= 2.6.0 =
**Security & Design update**: Multiple security fixes, redesigned chatbot UI, and critical bug fixes. Recommended update for all users.

= 2.2.0 =
**Major update**: Local Brain — privacy-first local AI processing. Zero API costs, works offline, full privacy.

= 2.1.0 =
WordPress Autopilot — AI agent that manages your site through chat.

= 2.0.0 =
Sentient Memory — AI learns from every interaction and improves over time.

= 1.4.0 =
Empathy Engine — AI now detects user emotion and adapts its tone.

= 1.3.0 =
Glass Box — See confidence scores and sources on every AI answer.

= 1.2.0 =
Multi-turn AI conversations and persistent chat history.

= 1.0.0 =
First release with multi-AI support.
