=== My Observer AI Shopping Assistant for WooCommerce – Product Q&A Chat ===
Contributors: DarrisB
Tags: woocommerce, chatbot, ai chatbot, product assistant, customer support
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 8.2
Stable tag: 2.1.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Let shoppers ask questions and get answers from your own products. Smart search is free through MyObserver; chat uses your own OpenAI or Claude key.

== Description ==
My Observer AI Shopping Assistant adds a chat box to your WooCommerce store. Shoppers ask questions in plain language ("Which of these is waterproof?", "What do you have under $50 for a gift?") and get answers based on your own products and the documents you upload, not on guesses from the internet.

How it works for you, the store owner:

* **Search is free.** Finding the right products for a question works through MyObserver at no cost. You connect it with one click in the plugin settings.
* **Chat uses your own AI key.** Answers are written by OpenAI or Claude using an API key from your own account, so you pay the AI provider directly. With gpt-4o-mini that is about $1 per 1,000 chats.
* **You stay in control.** Choose the provider and model, cap how long answers can be, and limit how many messages one visitor or your whole site can send.
* **It never breaks.** If smart search is not connected, or the service is busy, the chat falls back to normal keyword search of your catalog for that question.

This plugin is designed for merchants who want:
* Product-aware chat that can reference your catalog content
* Optional document-aware answers (shipping, sizing, care guides) linked to WooCommerce products
* A simple setup flow inside wp-admin
* Protection against runaway AI costs (answer length cap and message limits)
* A choice of OpenAI or Claude for the chat answers

How it works at a high level:
1. Your WooCommerce products are indexed. The text is turned into search vectors by the MyObserver search service (after you click Connect) and stored on your own site.
2. Optional TXT, CSV, DOCX, and text-based PDF files can be uploaded into the Product Intelligence Engine.
3. A shopper's question is matched against your products and documents.
4. Your chosen AI provider (OpenAI or Claude, with your own key) writes the final answer from what was found.

The storefront chat widget can be embedded with a shortcode or auto-injected in the footer, and the admin experience includes a modern settings screen for provider settings, limits and document management.

== Features ==
* Embedded storefront chat widget (`[myobserver_rag_widget]` shortcode, legacy `[rag_bot_widget]`, or footer auto-inject)
* Free smart search through MyObserver (opt-in, one-click Connect)
* Automatic keyword-search fallback when smart search is off or unavailable
* OpenAI or Claude for chat answers, using your own API key
* Answer length cap (100 to 2000 tokens, default 500)
* Message limits per visitor (default 20 per 10 minutes) and per site (default 300 per hour)
* Local vector storage and product indexing on your own server
* Product Intelligence Engine for document uploads, document-product linking, reindexing, and queue review
* TXT, CSV, DOCX, and text-based PDF ingest support
* "Rebuild index" action in the settings screen

Bundled build artifacts:
- This plugin ships compiled Angular assets in `assets/settings-ui/browser/`.
- Source repository (required for WordPress.org readability compliance): https://github.com/darrisb/woo-rag
- Build command example: `npm ci && npm run build`

== Screenshots ==
1. Main Settings: Configure provider, model, and storefront assistant behavior from one settings screen.
2. Storefront Chat Widget: Embedded chat experience on a WooCommerce storefront page using shortcode placement.
3. Diagnostics and Product Intelligence: Review local index health, run retrieval checks, upload knowledge documents, and manage document-product links.
4. API credentials
To display screenshots on WordPress.org, place image files in your plugin assets directory using names like `screenshot-1.png`, `screenshot-2.png`, etc.

== Frequently Asked Questions ==
= Does this plugin require WooCommerce? =
Yes. WooCommerce must be installed and active.

= Do I have to connect to MyObserver? =
No. Until you click Connect, nothing is sent to MyObserver and your store uses keyword search of your catalog. Connecting turns on smart search, which understands what the shopper means rather than only matching words.

= What does it cost? =
Smart search through MyObserver is free. Chat answers are paid to OpenAI or Anthropic with your own key. With gpt-4o-mini that is about $1 per 1,000 chats. You can limit answer length and the number of messages per visitor and per site.

= Is my OpenAI or Claude key shared with MyObserver? =
No. Your key is used only to talk to api.openai.com (OpenAI) or api.anthropic.com (Claude). It is never sent to MyObserver or anywhere else.

= Can I place the chat widget manually? =
Yes. Use `[myobserver_rag_widget]` (or legacy `[rag_bot_widget]`) in any page, post, or block shortcode element.

= Is product indexing automatic? =
Once smart search is connected, edited products are queued automatically via WP Cron. You can also run a full "Rebuild index" from `My Observer > RAG for WooCommerce`.

= I updated from an older version. Do I need to do anything? =
If your search index was built with OpenAI's text-embedding-3-small model (the default), it keeps working and you only need to click Connect. If it was built with any other model, or with the old Claude embeddings setting, the settings screen tells you to connect and rebuild the index. Until then your store uses keyword search.

= Why does Connect fail with an ownership check error? =
MyObserver confirms you own the site by fetching a short-lived code from `/wp-json/myobserver-rag/v1/search-verify` on your site. This fails on local or staging sites that are not reachable from the internet, when a security plugin blocks the WordPress REST API, or when a firewall blocks the request.

= Can I upload documents to improve retrieval? =
Yes. The Product Intelligence Engine lets you upload TXT, CSV, DOCX, and text-based PDF files, review them in the admin queue, and link them to WooCommerce products.

= Does this plugin include payment or subscription checkout by itself? =
Core storefront assistant functionality is in this plugin. Optional advanced add-ons are provided separately.

= Does this plugin require an external vector database? =
No. It uses a high-performance, file-based embedded vector database written in native PHP, separate from your MySQL database.

== Installation ==
1. Upload the plugin folder to `/wp-content/plugins/`.
2. Activate the plugin in WordPress.
3. Confirm WooCommerce is installed and active.
4. Go to `My Observer > RAG for WooCommerce`.
5. Add your `OpenAI API Key` or `Claude API Key` for chat answers and save.
6. Click Connect to turn on free smart search (optional).
7. Optionally upload knowledge documents in the Product Intelligence Engine section.
8. Add shortcode `[myobserver_rag_widget]` to a page, or enable auto inject.

== Usage ==
Storefront widget:
* Add `[myobserver_rag_widget]` where you want chat to render.
* If Auto Inject is enabled, chat can render in `wp_footer`.

Indexing:
* Go to `My Observer`.
* Connect smart search, then use `Rebuild index` to queue indexing for all products and documents.

Documents:
* Go to `My Observer`.
* In the Product Intelligence Engine section, upload TXT, CSV, DOCX, or text-based PDF files.
* Review linked products, update links, and queue document reindexing as needed.

== External services ==
This plugin can connect to third-party services based on your configuration.

1. OpenAI API (`https://api.openai.com`)
* Used for: chat answers when OpenAI is selected as the chat provider, and for listing the models available to your key.
* Data sent: your OpenAI API key (to OpenAI only) and the shopper's question with the product and document context needed to write the answer.
* Terms of Use: https://openai.com/policies/terms-of-use/
* Privacy Policy: https://openai.com/policies/privacy-policy/

2. Anthropic API (`https://api.anthropic.com`)
* Used for: chat answers when Claude is selected as the chat provider, and for listing the models available to your key.
* Data sent: your Claude API key (to Anthropic only) and the shopper's question with the product and document context needed to write the answer.
* Terms: https://www.anthropic.com/legal/commercial-terms
* Privacy Policy: https://www.anthropic.com/legal/privacy

3. MyObserver API (`https://api.myobserver.io`)
* Used for: free smart search. It runs only after an administrator clicks Connect in the plugin settings; until then nothing is sent and the site uses keyword search.
* Data sent when connecting: the site URL, the administrator email address and the plugin version. To prove you own the site, the service fetches a one-time code from `/wp-json/myobserver-rag/v1/search-verify` on your site; that route returns nothing except for a code that is valid for a few minutes.
* Data sent afterwards: product text, document text and shopper questions, so the service can turn them into search vectors. Your OpenAI or Claude key is never sent to MyObserver.
* Once a day while connected the plugin also checks the connection status and your daily usage.
* Terms: https://myobserver.io/terms
* Privacy Policy: https://myobserver.io/privacy

== Privacy ==
Review the included privacy policy template and update site policy text as needed for your deployment. Chat rate limiting uses a one-way hash of the visitor's connection address with a site-specific salt; the address itself is never stored.

== Changelog ==
= 2.1.0 =
* Smart search now runs through MyObserver and is free. It is opt-in: nothing is sent to MyObserver until you click Connect in the plugin settings. Your OpenAI or Claude key is only used for chat answers and is never sent to MyObserver.
* If smart search is not connected, or the service is busy or unavailable, the chat quietly uses keyword search of your catalog instead, so it keeps working.
* Products and documents that could not be indexed are retried automatically in the background.
* Updating from an earlier version: an index built with OpenAI text-embedding-3-small is kept as it is. An index built with any other model, or with the old Claude embeddings setting, needs one click on Rebuild index after connecting. The settings screen explains this.
* New: message limits to protect your AI bill. By default each visitor can send 20 messages per 10 minutes and the whole site 300 per hour. Visitors who go over see a friendly message. Both limits can be changed.
* New: a cap on how long chat answers can be (default 500 tokens, between 100 and 2000).
* Chat now remembers 4 turns of conversation by default instead of 10, which lowers cost. Your saved value is not changed.
* Claude chat now defaults to Claude Haiku 5.5. Sites still using a retired Claude 3 model are moved to it automatically.
* Claude instructions are now sent in Claude's dedicated system field, which follows them more reliably.
* Removed the custom Claude embeddings endpoint, and the option to create search vectors with your own OpenAI or Claude key. Search vectors now come only from MyObserver.
* Hosted chat and remote catalog sync are not part of this release.
* The plugin is now named "My Observer AI Shopping Assistant for WooCommerce – Product Q&A Chat".

= 2.0.3 =
* Added a customer-safe fallback response when a hosted store reaches its monthly chat allowance, without exposing plan, billing, credit, or upgrade details in the storefront chat.
* Added hosted monthly message usage to the admin UI, including the current usage, limit, reset date, and an Upgrade to Pro action for free stores that reach their allowance.
* Prevented chat attempts made after the monthly allowance is exhausted from increasing the usage counter.
* Added persistent hosted storage for original uploaded document files, with tenant-isolated references and cleanup when a document is replaced or deleted.
* Added hosted document upload limits and clearer storage-limit errors based on the active plan.
* Added hosted mode.

= 2.0.2 =
* Updated release packaging and docs for the current `My Observer > RAG for WooCommerce` admin path.
* Refined admin labeling so the release matches the current Woo-RAG WordPress menu.

= 2.0.1 =
* Updated broken links in chat window.

= 2.0.0 =
* Added the new Angular-powered admin settings experience for `My Observer > RAG for WooCommerce`.
* Added the Product Intelligence Engine for document uploads, document-to-product linking, queue review, and document reindex actions.
* Extended retrieval so uploaded document knowledge can be searched alongside WooCommerce product context.
* Added PDF text extraction support for text-based PDFs during document ingest.
* Improved WordPress admin runtime loading and nonce/config bootstrapping for the new settings UI.
* Cleaned plugin packaging and install structure for WordPress upload/activation compatibility.
* Added built-in diagnostics views for index health, retrieval testing, and live product/document vector reporting.
* Improved the document library UI with queue-style browsing, document totals, inline status messaging, and modal-based linked product review.
* Added document delete actions with automatic vector-store compaction so document counts and storage feedback update more reliably after cleanup.
* Improved full product reindex behavior to rebuild cleanly, compact the local vector store, and report more accurate live index counts.
* Added page-aware storefront chat context so retrieval can prefer the current product, listing, search, cart, or checkout context when relevant.
* Improved local widget and settings UX with better overflow handling, right-aligned save actions, overlay diagnostics results, and immediate readiness updates after saving API credentials.
* Hardened API key handling so saved keys are not returned to the enhanced UI or printed into fallback settings fields.
* Changed the shipped extension manifest to an empty tabs list so production installs do not expose premium placeholder tabs by default.

= 1.0.0 =
* Initial public release.
