=== Mind Web Concierge ===
Contributors: mindwebconcierge
Tags: ai-chatbot, customer-support, automation, rag, artificial-intelligence, concierge
Requires at least: 6.0
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.3.0
License: GPL-2.0+
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Mind Web Concierge is an intelligent WordPress assistant powered by RAG technology. It acts as a digital concierge for your website - guiding users through content and delivering the right answers at the right moment.

== Description ==

Mind Web Concierge brings intelligent AI assistance directly to your WordPress website. Powered by RAG (Retrieval-Augmented Generation) technology, it understands your content and delivers accurate, context-aware responses to your visitors in real time.

It allows you to:

* Provide instant automated responses to visitors
* Improve customer engagement and retention
* Reduce support workload
* Deliver 24/7 AI-powered assistance
* Index WordPress posts, pages, and WooCommerce products automatically
* Connect any OpenAI-compatible language model via the LLM settings panel
* Link a Mind Spaces workspace where you can upload documents and ask questions about them directly
* Use Local Thinking mode to let visitors ask questions focused on the current page content and any linked Mind Spaces notebooks assigned to that page

Perfect for:

* Business websites
* E-commerce stores
* Service providers
* Corporate portals

Easy to install, configure, and scale.

== Data Handling ==

This plugin stores chatbot conversation logs and metadata in the WordPress database. The following visitor data is collected per conversation: session ID, IP address, screen resolution, user agent (browser info), accepted language, referrer URL, timezone, and platform. Data is accessible only to authorized administrators. Depending on configuration, conversation content may be sent to external services for AI processing.

== External Services ==

This plugin connects to the following external services operated by Smart Processes. Data is transmitted to these services during normal plugin operation.

= RAG API =
* URL: https://rag.smartprocesses.cloud
* Purpose: Content indexing, category management, and AI-generated streaming responses.
* Data sent: WordPress post content, WooCommerce product data, visitor questions.

= Mind Spaces API =
* URL: https://spaces.smartmind.services
* Purpose: Authentication, space retrieval, document-based knowledge access, and knowledge base management.
* Data sent: Authentication tokens derived from administrator login, space queries, and related knowledge base requests.

Mind Spaces is the knowledge management platform behind Mind Web Concierge. It lets you manage spaces (knowledge bases), upload documents, and ask questions directly to test AI responses. For more information visit: https://spaces.smartmind.services

= Subscription API =
* URL: https://subscriptions.smartprocesses.cloud
* Purpose: Retrieves pricing information and handles subscription billing and management via Stripe, including trial creation, subscription retrieval, cancellations, reactivations, and invoice downloads.
* Data sent: App GUID, customer email, Stripe product ID.

= Smart Mind Website =
* URL: https://smartmind.it
* Purpose: Provides product information, legal pages, optional pricing display, and the optional "Powered by" link shown in the chatbot widget.
* Data sent: No personal visitor data is intentionally transmitted by the plugin to this website during normal operation.

The plugin may display links to Smart Mind legal or product pages for administrator reference and optional front-end branding. These links do not process visitor chat content.

The plugin communicates with Smart Processes services only for features explicitly enabled and used by the site administrator, such as AI responses, content indexing, notebook access, pricing retrieval, and subscription management. No personal user data is transmitted without the administrator's configuration and the visitor's direct interaction with the chatbot.

* Privacy Policy: https://smartmind.it/mind-web-privacy-policy/
* Terms of Service: https://smartmind.it/mind-web-terms-of-service/

== Installation ==

1. Upload the plugin folder to `/wp-content/plugins/mind-web-concierge`, or install directly through the WordPress Plugins screen.
2. Activate the plugin through the **Plugins** menu in WordPress.
3. Navigate to **Mind Web** in the WordPress admin dashboard.
4. Configure the plugin settings.
5. Index your posts, pages, and/or WooCommerce products from the Indexing tab.

Alternatively, install via the WordPress Plugin Directory:

1. Go to **Plugins > Add New**.
2. Search for "Mind Web Concierge".
3. Click **Install Now**.
4. Activate the plugin.

== Frequently Asked Questions ==

= Do I need an external account? =

Yes. An account with Mind Spaces is required to use the AI service.
Register at:
https://spaces.smartmind.services/Identity/Account/Register
After registration, log in at Mind Spaces Settings and start using the features.

= Does the plugin include a sitemap? =

Yes. The plugin generates its own lightweight XML sitemap based on your WordPress navigation menus. It is accessible at:

  https://yoursite.com/?mindweco_sitemap=1

No additional sitemap plugin is required.

= Does this plugin slow down my website? =

No. The plugin is optimized for performance and loads efficiently. Streaming responses use a lightweight SSE connection that does not block page rendering.

= Is WooCommerce required? =

No. The plugin works with standard WordPress posts and pages. WooCommerce product indexing is available as an optional feature when WooCommerce is installed and active.

= Is it GDPR compliant? =

The plugin stores conversation metadata (IP address, user agent, screen resolution, timezone, platform, referrer, and accepted language) in the WordPress database. Visitor questions and site content are also transmitted to external services operated by Smart Processes. Please disclose this in your site's privacy policy and ensure you have a lawful basis for processing this data under GDPR.

= What language models are supported? =

Any OpenAI-compatible language model can be configured via the LLM settings panel by providing a model name, base URL, API key, and provider name.

= Why does the plugin use cURL directly? =

The WordPress HTTP API does not natively support Server-Sent Events (SSE) streaming. cURL is used exclusively for streaming responses and is the only available method for this functionality.

= How does the plugin handle sessions? =

The plugin uses a tab-scoped session ID to track visitor conversations. A UUID v4 is stored in `sessionStorage` and sent with each frontend chat request, so refreshes and same-tab navigation keep the same conversation while closing the tab or browser starts a new one.

= What is the Local Thinking checkbox? =

When enabled, the **Local Thinking** option switches the chatbot into a focused mode that answers based on the current page content only.

> Mind Web will focus only on information available on this page to provide contextual answers.

If the current page also has Mind Spaces notebooks assigned to it (via the Notebooks settings), those notebooks are included in the response context as well. This is useful for single-product pages, landing pages, or any page where you want the AI to answer based on a specific, scoped set of content rather than your entire indexed knowledge base.

= When does the chat icon appear on my website? =

The chat icon is always visible on your website. If your subscription has expired or is not active, an informational message will be displayed inside the chat widget notifying the visitor that they are using the free version. You can check and manage your subscription from the Mind Web admin panel.

= Does the plugin use browser storage? =

Yes. The plugin stores small amounts of data in the visitor's browser localStorage to preserve UI preferences such as theme selection, pinned messages, and citation references. It also uses `sessionStorage` for the current chat session ID, the conversation ID, and the Local Thinking toggle state so a refresh keeps the same chat in the same tab without carrying it to a new tab or browser session. No personal data is stored. All data remains on the visitor's device and is never transmitted to external servers.

= Does the plugin use WP-Cron? =

Yes. The plugin schedules a daily WP-Cron event (`mindweco_cleanup_transients`) to remove expired session transients from the database. This keeps the database clean without affecting active visitor sessions. The cron job is automatically removed when the plugin is deactivated or deleted.

== Plugin Constants ==

The plugin defines the following internal constants. These are set automatically and do not require manual configuration.

= MINDWECO_RAG_URL =
The base URL for the RAG API service. Used for all indexing, category management, and streaming ask requests.
Value: `https://rag.smartprocesses.cloud`

= MINDWECO_NOTEBOOKS_URL =
The base URL for the Mind Spaces (Notebooks) service. Used for authentication, notebook retrieval, and knowledge base management.
Value: `https://spaces.smartmind.services`

= MINDWECO_STRIPE_URL =
The base URL for the Stripe subscription management API. Used for trial creation, subscription status, cancellation, reactivation, and invoice downloads.
Value: `https://subscriptions.smartprocesses.cloud/api`

= MINDWECO_PROD_ID =
The Stripe Product ID associated with this plugin's subscription plan. Passed automatically when creating trial subscriptions.
Value: `prod_U3VYkOBf6Ngqi3`

= MINDWECO_POWER_BY =
The URL of the service provider's product page. Used to display an optional "Powered by" link in the chatbot widget when enabled by the administrator.
Value: `https://smartmind.it/`

== API Reference ==

The plugin communicates with external services through the following internal functions.

= Authentication & Token Management =

**mindweco_plugin_api_login( $base_url, $username, $password )**
Authenticates with the RAG API and retrieves an access token.

**mindweco_plugin_refresh_token()**
Refreshes the main RAG API access token using stored credentials.

**mindweco_plugin_knowledge_repository_get_token()**
Returns a valid knowledge repository token, refreshing automatically if expired.

**mindweco_plugin_knowledge_repository_refresh_token()**
Refreshes the knowledge repository token using stored credentials.

**mindweco_plugin_knowledge_repository_login_with_cookie( $base_url, $username, $password, $external_id, $external_name, $type )**
Authenticates with the knowledge repository (Mind Spaces) and retrieves an auth token. Also registers the current indexing configuration as an external app connection.

**mindweco_plugin_knowledge_repository_logout( $base_url, $external_app_id, $user_id )**
Removes the external app connection from the knowledge repository and clears stored credentials.

= Categories =

**mindweco_plugin_api_create_category( $base_url, $token, $name, $indexing_id, $sitemap_xml, $language, $parent_id )**
Creates a new content category in the RAG service. Called automatically on plugin activation using the site's nav menu sitemap.

**mindweco_plugin_api_get_categories( $base_url, $token )**
Retrieves all categories for the authenticated account.

= Indexing =

**mindweco_plugin_api_index_items( $base_url, $token, $category_id, $chunk_size, $chunk_overlap, $url, $wp_json, $header_levels, $meta, $local_item_id )**
Indexes a WordPress post or page into the knowledge base. Also called automatically when a post is published or updated via the `transition_post_status` hook.

**mindweco_plugin_api_index_products( $base_url, $token, $category_id, $chunk_size, $chunk_overlap, $product_json, $meta, $local_item_id )**
Indexes a WooCommerce product into the knowledge base.

**mindweco_plugin_api_delete_indexed_items( $base_url, $token, $category_id, $item_id )**
Deletes a previously indexed item. Also called automatically when a post is trashed or permanently deleted via the `before_delete_post` and `wp_trash_post` hooks.

= Streaming / Ask =

**mindweco_ask_page_based_ref( $base_url, $token, $question, $category_id, $category_ids, $top_k, $app_guid, $callback, $items_ids, $conversation_id )**
Sends a question to the streaming endpoint and delivers the response via Server-Sent Events (SSE). Uses cURL exclusively because the WordPress HTTP API does not support streaming callbacks. Supports multi-category queries and item-level filtering for Local Thinking mode.

= Stripe / Subscriptions =

**mindweco_stripe_add_trial( $stripe_base_url, $app_guid, $product_id, $customer_email, $title, $site_base_url )**
Creates a Stripe trial subscription and a new RAG user account simultaneously. Called on plugin activation.

**mindweco_stripe_add_trial_without_user( $stripe_base_url, $app_guid, $product_id, $customer_email )**
Creates a Stripe trial subscription without creating a user account.

**mindweco_stripe_active_subscription( $stripe_base_url, $app_guid )**
Retrieves the currently active Stripe subscription for a given app GUID. Called periodically via `mindweco_periodic_subscription_check` (every 30 minutes) to keep subscription status in sync.

**mindweco_get_all_subscriptions( $stripe_base_url, $app_guid )**
Retrieves all Stripe subscriptions for a given app GUID.

**mindweco_get_history_subscription( $stripe_base_url, $app_guid )**
Retrieves the full subscription history for a given app GUID.

**mindweco_plugin_cancel_subscription( $stripe_base_url, $app_guid, $subscription_id, $cancel )**
Cancels an active Stripe subscription. Also called automatically on plugin deactivation.

**mindweco_plugin_reactivate_subscription( $stripe_base_url, $app_guid, $subscription_id, $cancel )**
Reactivates a previously cancelled Stripe subscription.

**mindweco_download_subscription_invoice( $stripe_base_url, $invoice_number )**
Retrieves the PDF download URL for a given invoice number.

= LLM Configuration =

**mindweco_plugin_create_attach_llm_to_config( $base_url, $token, $name, $llm_base_url, $model_name, $provider, $api_key, $indexing_id )**
Creates a new LLM configuration and attaches it to an existing indexing configuration. The API key is encrypted before being stored using AES-256-CBC via `mindweco_encrypt_api_key()`.

**mindweco_plugin_update_llm_config( $base_url, $token, $llm_id, $name, $api_key, $llm_base_url, $model_name, $user_id )**
Updates an existing LLM configuration.

**mindweco_plugin_delete_llm_config( $base_url, $token, $llm_id )**
Deletes an LLM configuration by ID and clears all related options from the WordPress database.

= Mind Spaces / Notebooks =

**mindweco_plugin_get_notebooks( $base_url, $token )**
Retrieves all notebooks (spaces) from the Mind Spaces knowledge repository.

= Page-Based Notebooks =

Notebooks can be assigned to specific WordPress pages via the admin UI. These mappings are stored in the `mindweco_page_based_notebooks` option as an array keyed by page ID, each containing a `title` and a `notebooks` array of notebook IDs.

At runtime, `mindweco_get_notebooks_for_page( $post_id )` looks up the current page's title and returns its assigned notebook IDs. These are merged into the category_ids sent to the streaming endpoint.

== Screenshots ==

1. Chat interface on the website front end.
2. Admin configuration panel.
3. AI response example.
4. Mobile responsive view.

== Installation Videos ==

1. Upload Plugin Method:
https://www.youtube.com/watch?v=Y8d5Sn0xg2I

2. Install via WordPress Search:
https://www.youtube.com/watch?v=x5ihEikliVE

== Changelog ==

= 1.3.0 =
* Removed conversation history from the Conversation Info Button.
* Conversation history is now accessible only via the "See Chat" view.
* Added an attention attraction component that appears once to invite website visitors to start a chat.
* The attention attraction component is displayed 5 seconds after the visitor arrives on the website.

= 1.2.9 =
* Improved the way unanswered questions are stored and displayed in the Conversation Panel.

= 1.2.8 =
* Added a Delete Service option in the plugin settings to allow administrators to remove services directly from the service list.
* Introduced a dedicated delete button for faster and easier service management.
* Improved service administration by making it easier to organize and maintain configured services.

= 1.2.7 =
* Added Custom CSS support for iframe content.
* Added a new Custom CSS field in plugin settings.
* Improved iframe customization options.
* Enhanced plugin flexibility for embedded content styling.

= 1.2.6 = 
* Added live operator chat with real-time socket communication, allowing support agents to join active conversations instantly.
* Improved human handoff flow between AI responses and live operators for a smoother support experience.
* Preserved existing tab-based chat sessions, ensuring conversations remain available during page refreshes and same-tab navigation.
* Enhanced overall chat continuity and reliability without affecting existing plugin functionality.

= 1.2.5 =
* Improved the admin tour for Item Settings with clearer, more descriptive guidance.
* Added tour steps for the Services & Options section.
* Added separate tour guidance for service count, service title, and service URL fields.
* Removed a tour step that pointed to an outdated/nonexistent service widget setting.
* Added stable selectors for service fields so the tour can target them reliably.

= 1.2.4 =
* Added new swap functionality improvements.
* Improved modal behavior when services are unavailable.
* Applied minor stability and usability improvements.

= 1.2.3 =
* Added functionality to resize Services and Sources panels.
* Added functionality to drag and reposition the chat window.
* Improved chat window interaction and usability.

= 1.2.2 =
* Fixed: Pressing Enter during bot response no longer sends a new message
* Fixed: Clicking follow-up suggestion buttons during bot response no longer triggers a new request

= 1.2.1 =
* Fixed rendering issues with Markdown output using Marked.js.
* Improved citations rendering to ensure consistent display across responses.
* Minor UI and formatting fixes for better stability.

= 1.2.0 =
* Added Markdown support using marked.js.
* Improved response formatting with support for headings, lists, links, and code blocks.
* Enhanced chat readability and overall user experience.

= 1.1.9 =
* Unanswered Questions tab now shows today’s unanswered questions by default and loads all results based on the selected date filter.
* Enhanced Conversations table for improved readability and user experience.

= 1.1.8 =
  * Redesigned the Conversations admin interface .
  * Added a dedicated Unanswered Questions tab to separate unanswered items from completed conversations.
  * Improved the See Chat modal with a structured Conversation Details view, including summary information and question-and-response history.
  * Added a PDF download option for conversation details.
  * Updated the conversation PDF layout with improved styling, formal wording, and more readable timestamps.
  * Replaced the previous toggle-style interaction with clearer action buttons.
  * Added quick-access buttons to view related services and sources.
  * Improved date filtering so conversations load automatically after selecting an end date.
  * Removed the Apply Filter button to simplify the workflow.
  * Improved mobile responsiveness and visual consistency across the Conversations page.

= 1.1.7 =
* Fixed chat widget positioning on some WordPress themes where the chat window could appear inside the page flow.
* Improved chat/modal overlay behavior so it stays attached to the browser viewport instead of being affected by theme containers.
* Increased widget overlay stacking priority so sticky headers/navbars no longer cover the opened chat.
* Improved reliability of the floating chat button, chat panel, service panel, and citation popup layering across themes.
* Added a front-end safeguard that mounts the chat UI directly under the <body> element for better compatibility with custom theme layouts.

= 1.1.6 =
* Added: References panel in chat with dynamic source display.
* Added: Toggle icons (calendar/link) to show/hide references.
* Added: Search functionality when more than 8 services are available.

* Improved: Service rendering logic:
  - Single service is displayed by default.
  - Multiple services are shown as cards.
* Improved: References can be accessed directly from chat via toggle interaction.
* Improved: If no services are configured, the references panel is displayed by default.

* Changed: Replaced calendar icon with services icon for better clarity.

= 1.1.5 =
* Improved: Citation popup closing behavior.

= 1.1.4 =
* Added: Configurable number of services in "Services & Options"
* Added: Ability to define custom service names and links
* Added: Support for multiple service cards in chat interface

= 1.1.3 =
* New: Media files indexing feature

= 1.1.2 =
* Replaced Shepherd.js with Driver.js for the onboarding tour. Driver.js is MIT-licensed and fully compatible with the GPL-2.0+ license of this plugin.
* Changed #mindweco-context-toggle storage from localStorage to sessionStorage — toggle state now persists only for the current browser tab/session.

= 1.1.1 =
* Security: Encrypted access tokens and API credentials at rest.
* Improved error handling and user-facing messages.
* Added daily WP-Cron cleanup for expired session transients.
* Upgraded Shepherd.js to 11.2.0 (.min.js build used for WordPress compatibility, 
  as the latest release ships as .mjs which is not supported in this context).
* All plugin code now uses the WordPress HTTP API where possible. cURL is retained 
  only for SSE streaming endpoints, as the WordPress HTTP API cannot natively handle 
  real-time incremental responses. All inputs are sanitized and outputs properly escaped.
* Code quality and WordPress standards improvements.
* Bug fixes and stability improvements.

= 1.1.0 =
* Improved compatibility with latest WordPress version.
* Enhanced security by adding proper nonce verification and permission checks.
* Improved data escaping and sanitization across plugin outputs.
* Refactored codebase to use consistent and unique prefixes.
* Updated external service documentation and compliance details.
* Fixed minor bugs and improved overall stability.

= 1.0.0 =
* Initial release.

== Privacy Policy ==

This plugin transmits the following data to external services operated by Smart Processes:

* WordPress post and page content (for indexing)
* WooCommerce product data (for indexing, if WooCommerce is active)
* Visitor questions typed into the chat widget
* Authentication tokens derived from administrator login (for API authentication)
* Customer email and subscription data (for Stripe billing)

The following visitor metadata is stored in the WordPress database per conversation session:

* IP address
* User agent (browser and OS information)
* Screen resolution
* Accepted language
* Referrer URL
* Timezone
* Platform

Data is transmitted to the following services:

* RAG API: https://rag.smartprocesses.cloud
* Mind Spaces: https://spaces.smartmind.services
* Subscription API: https://subscriptions.smartprocesses.cloud/api
* Smart Mind Website: https://smartmind.it

A tab-scoped session ID is stored in `sessionStorage` and used to keep a conversation alive across refreshes and same-tab navigation. Closing the tab or browser starts a new conversation.

Access tokens and passwords are encrypted at rest in the WordPress database 
using AES-256-CBC encryption tied to the site's unique AUTH_KEY.

= Browser Local Storage =

This plugin stores the following data in the visitor's browser localStorage to preserve UI preferences across page loads:

* mindweco-theme-mode - stores the visitor's preferred color theme (light or dark).
* pinned_{message_id} - stores which chat messages the visitor has pinned.
* cit_{message_id} - stores citation/source references for bot responses.

The following values are stored in `sessionStorage` so the current chat keeps its state only for the active tab:

* mindweco_tab_session_id - stores the current tab's chat session ID.
* mindweco_conversation_id - stores the active remote conversation ID.
* mindweco_ask_only_current_page_{post_id} - stores the state of the Local Thinking toggle per page.

All data is stored locally in the visitor's browser only. None of this data is transmitted to external servers. It is automatically cleared when the visitor starts a new chat session.

The subscription service may also be contacted server-side to retrieve pricing and billing-related information for the plugin's subscription features.

The Smart Mind website may be referenced for legal pages, product information, optional pricing display, and optional front-end branding links.

For full details on how data is collected, processed, and protected, please refer to our Privacy Policy:
https://smartmind.it/mind-web-privacy-policy/
