=== NKA AI Support ===
Contributors: nka, adrianoicv
Tags: live chat, customer support, helpdesk, support ticket, ai chatbot
Requires at least: 6.5
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 0.9.500
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Live chat support for WordPress: a front-end widget, a full admin inbox, and optional AI replies grounded in your own content.

== Description ==

NKA AI Support is a complete customer support solution for WordPress. Visitors
get a floating chat widget; your team answers from a full support inbox inside
the WordPress admin. Everything you need to run support is included for free and
works out of the box, with no account and no external service.

When you want to scale, you can connect an NKA account to add AI replies that
answer from your own site content and documents, so routine questions are
handled automatically and your team only steps in when it matters.

**Free, no account required:**

* A floating chat widget for visitors
* A support inbox in the WordPress admin: reply, assign, prioritise, tag and take notes
* Session lifecycle management (open, solved, unsolved, closed, spam, archived)
* Persistent conversation history stored in your own database
* Email notifications to your team for new conversations and visitor replies, to one or more addresses
* Spam protection: per-visitor rate limits and a maximum message length
* Privacy tools: optional automatic deletion of old conversations, WordPress personal-data export and erase, suggested privacy-policy text, and an opt-in to remove all plugin data when the plugin is deleted
* Widget appearance and colour customisation
* Portuguese-ready translations via the `nka-ai-support` text domain

Without a connected account, every conversation is routed straight to your team,
so the plugin is a fully working live-chat support desk on its own.

**With a connected NKA account (paid), the chat also answers on its own:**

* Streaming AI replies through an LLM provider of your choice
* Answers grounded in your own content, so the assistant does not invent facts
* Hybrid-search retrieval against a central NKA knowledge-base service
* Knowledge-base indexing for posts, pages, and WooCommerce products
* Upload your own PDF and Markdown documents as source material
* WooCommerce product recommendations rendered as real product cards
* Automatic handover to your team when the visitor asks for a person

The AI layer is additive. Turn it off, or never connect an account, and the
support desk keeps working exactly as before.

== External Services ==

This plugin relies on external services only for the optional AI features. The
support desk itself - the chat widget, the admin inbox, conversation history and
human replies - works entirely within your WordPress site and contacts no
external service.

No assets are loaded from third-party CDNs. The Inter and Roboto webfonts are
bundled with the plugin and served from your own site, so no visitor data is
sent to a font provider.

**1. NKA AI Support service (api.ai.nka.pt)**

Operated by NKA, this service creates and manages your subscription to the AI
features, and provides the knowledge-base retrieval that grounds AI answers in
your site content.

It is contacted in these cases:

* When an administrator clicks `Connect account` in the plugin settings, to create or link a subscription. Sends your site URL and the email address of the administrator performing the action.
* On each plugin settings page load, to check whether the subscription is still valid. Sends your site URL.
* When content is indexed, to store text extracted from the posts, pages, products and uploaded documents you choose to index.
* When a visitor sends a chat message on a connected site, to retrieve the passages of your content most relevant to their question. Sends the visitor's question.
* When NKA AI is the selected AI provider, for each AI reply (see "2. NKA AI" below).

Terms and conditions: https://nka.pt/termos-e-condicoes/
Privacy policy: https://nka.pt/politica-privacidade/

The following AI providers are built into the plugin. The plugin contacts only
the provider that you select: NKA AI (the default, no API key), or another
provider that you configure with your own API key. It sends no data to
an AI provider until you enable AI replies and a visitor sends a chat message.
For each AI reply, the selected provider receives the visitor's message, recent
conversation history, the system instructions that control the assistant, and
relevant passages from the content that you chose to index. The plugin also
sends your API key (or, for NKA AI, your site's NKA key) in the request
authorisation header. This data allows the provider to generate the AI reply.

**2. NKA AI**

NKA AI is the default AI provider and uses the credits of your NKA subscription.
For each AI reply, NKA's gateway (api.ai.nka.pt) receives the data described
above and forwards it to a language-model provider chosen by NKA, which
generates the reply. NKA picks and changes these providers on its side, without
a plugin update. At the time of this release they are OpenAI and OpenRouter,
both based in the United States. NKA does not keep the content of the messages: the gateway records only usage figures for billing (token counts and
cost), and the retrieval service does not log the visitor's question.

OpenRouter routes each request to the model's own provider (for example NVIDIA).
OpenRouter terms of service: https://openrouter.ai/terms
OpenRouter privacy policy: https://openrouter.ai/privacy
OpenAI terms and privacy policy: see "3. OpenAI" below.

Terms and conditions: https://nka.pt/termos-e-condicoes/
Privacy policy: https://nka.pt/politica-privacidade/

**3. OpenAI**

OpenAI provides language models used to generate AI replies when you select
OpenAI as the provider. OpenAI receives the data described above for each
visitor message that triggers an AI reply.

Terms of use: https://openai.com/pt-PT/policies/row-terms-of-use/
Privacy policy: https://openai.com/policies/privacy-policy/

**4. Groq**

Groq provides language-model inference used to generate AI replies when you
select Groq as the provider. Groq receives the data described above for each
visitor message that triggers an AI reply.

Terms of use: https://groq.com/terms-of-use
Privacy policy: https://groq.com/privacy-policy

**5. Mistral AI**

Mistral AI provides language models used to generate AI replies when you select
Mistral AI as the provider. Mistral AI receives the data described above for
each visitor message that triggers an AI reply.

Terms of use: https://legal.mistral.ai/terms
Privacy policy: https://legal.mistral.ai/terms/privacy-policy

**6. Google Gemini**

Google provides the Gemini API, which supplies language models used to generate
AI replies when you select Google Gemini as the provider. Google receives the
data described above for each visitor message that triggers an AI reply.

Terms of use: https://ai.google.dev/gemini-api/terms
Privacy policy: https://policies.google.com/privacy

As the site owner, you are responsible for disclosing this processing to your
visitors and for complying with the privacy laws that apply to you. An AI message
notice is configurable on the plugin's settings. Settings → Privacy → Policy
Guide offers suggested text that names the provider your site uses.

== Source Code and Build Process ==

This plugin contains no obfuscated code. The complete, human-readable source for
every compiled asset is included in the distributed plugin ZIP under `src/`,
together with the build configuration (`package.json`, `package-lock.json` and
`vite.config.js`). Nothing has to be downloaded from anywhere to read, study,
modify or rebuild the front-end code.

= Building the assets =

Requirements: Node.js 20 or later, and npm.

`cd wp-content/plugins/nka-ai-support`
`npm install`
`npm run build`

`npm run build` runs Vite and regenerates the entire `dist/` directory from
`src/`. `npm run dev` starts Vite in watch mode and rebuilds `dist/` on every
save.

= Which source file produces which bundle =

The build entry points are declared in `vite.config.js`:

* `src/main.jsx` produces `dist/main.js` (the front-end chat widget)
* `src/admin/settings.jsx` produces `dist/admin-settings.js`
* `src/admin/appearance.jsx` produces `dist/admin-appearance.js`
* `src/admin/inbox.jsx` produces `dist/admin-inbox.js`
* `src/admin/kb.jsx` produces `dist/admin-kb.js`

The stylesheets come from `src/widget.css` (which produces `dist/main.css`) and
`src/admin/admin-islands.css` (which produces `dist/admin-islands.css`).

`dist/` additionally contains files whose names carry a hash, for example
`dist/vendor-react-BMefg5gZ.js`, `dist/Popover-DijB5w4n.js` and
`dist/rolldown-runtime-CUp1htVo.js`. These are not hand-written files and do not
correspond to any single file in `src/`: they are the shared code-split chunks
that Vite generates automatically from the entry points above and from the
third-party libraries listed below. The hash in the filename changes whenever the
chunk's contents change. Running `npm run build` reproduces all of them.

= Third-party libraries bundled into dist/ =

The exact versions are pinned in `package-lock.json`, which is included in the
ZIP. All of these are free software under GPL-compatible licences.

* React and ReactDOM - MIT - https://github.com/facebook/react
* MUI (Material UI) and MUI Icons - MIT - https://github.com/mui/material-ui
* Emotion - MIT - https://github.com/emotion-js/emotion
* assistant-ui - MIT - https://github.com/assistant-ui/assistant-ui
* react-markdown - MIT - https://github.com/remarkjs/react-markdown
* remark-gfm - MIT - https://github.com/remarkjs/remark-gfm
* WordPress i18n (@wordpress/i18n) - GPL-2.0-or-later - https://github.com/WordPress/gutenberg
* Inter webfont, via Fontsource - OFL-1.1 - https://github.com/rsms/inter
* Roboto webfont, via Fontsource - OFL-1.1 - https://github.com/googlefonts/roboto

Vite is a build-time dependency only and is not shipped in `dist/`:
https://github.com/vitejs/vite

== Installation ==

Install and activate the plugin. The chat widget and the support inbox work out
of the box with no configuration - visitor conversations arrive under
`NKA AI Support > Support Inbox`, ready for your team to answer. Appearance and
behaviour can be customised from the plugin settings.

To add AI replies (paid):

1. Open `NKA AI Support > Settings`.
2. Click `Connect account` to link your NKA account.
3. Configure the LLM provider credentials.
4. Reindex the site content from the plugin admin tab (`NKA AI Support > Knowledge Base`).

== Frequently Asked Questions ==

= Does this plugin work without a connected NKA account? =

Yes. The plugin is a complete live-chat support desk on its own: the floating widget, the admin support inbox, conversation history, session management and email notifications all work for free with no configuration and no external service. Without a connected NKA account, incoming chats are routed straight to your team, who reply from the WordPress admin. Connecting an account adds AI replies and knowledge-base retrieval on top (see Installation).

= Is this an AI chatbot or a support plugin? =

It is a support plugin first. The chat widget and admin inbox are the product, and they work without any AI at all. The AI layer is an optional paid addition that answers routine questions from your own content and hands over to your team when needed - it never replaces the human side.

= Does this plugin require WooCommerce? =

No. WooCommerce support is optional and enabled only when WooCommerce is active.

= Where is the source code for the compiled assets? =

It ships inside the plugin. The uncompiled React and CSS sources are in `src/`,
and the build configuration is in `package.json`, `package-lock.json` and
`vite.config.js`. See the "Source Code and Build Process" section above for the
build commands and the list of bundled third-party libraries.

= Can developers change the chat texts per language or hide categories? =

Yes, with three filters:

* `nkasupp_widget_texts` receives the chat texts (welcome message, notice,
  suggestions, automatic reply, labels) and the page locale, and returns the
  texts to show. Use it to supply texts per language when the site runs
  TranslatePress, WPML or Polylang.
* `nkasupp_conversation_lang_detect` receives the detected language code
  (or null) and the visitor's message, and returns the code to store.
* `nkasupp_hidden_product_categories` receives the product category slugs the
  AI never shows to visitors (by default WooCommerce's default category,
  usually "Uncategorized") and returns the full list.

= Where are conversations stored? =

The plugin stores conversation and session data in custom WordPress database tables created on activation.

== Changelog ==

= 0.9.500 =

* The reindex panel no longer shows the search service's queue counts. It
  still lists posts that could not be indexed, with the "Retry failed" button.
* The Knowledge Base reindex bar counts documents instead of posts.

= 0.9.352 =

* Indexing runs in the background on the search service. The reindex panel
  shows what is still waiting there, lists posts that could not be indexed,
  and has a "Retry failed" button.
* Product search reranks fewer candidates, so answers come faster with the
  same quality.

= 0.9.351 =

* Product search decides that a question is off-topic using the new search
  model's scale. Install this version before the search service switches
  models.

= 0.9.350 =

* Knowledge Base documents: choose where each document's "Read more" leads,
  from the links found in the file, any page of this site, or an external URL.
  The assistant no longer links to the uploaded file itself.
* The assistant is told today's date and time in the site's timezone, so it can
  tell whether a campaign or deadline is in effect.
* Pages are indexed as visitors see them, including Elementor and other page
  builders, instead of the stored post content. Saving an Elementor template or
  global widget reindexes the pages that use it.
* A reply that comes back malformed from the language model is never shown to
  the visitor: the assistant uses its earlier answer, asks once more, or asks
  the visitor for more details.
* "Automatically reindex on save" is now on by default, and is switched on once
  for existing sites. Turn it off in the Knowledge Base if you prefer.
* Removed the "Log token usage" option from the Knowledge Base screen.
* Privacy policy suggested text: clearer wording on where NKA's language-model
  providers are based.

= 0.9.300 =

* The setup guide on the Appearance page now includes the teaser message and
  the human takeover message.
* "Run setup again" moved to the right end of the admin tab bar.
* Added a Dismiss button to the paused-setup notice and to the setup guide, so
  a setup restarted by mistake can be closed without walking every step.
* The suggested privacy-policy text now names who receives visitors' messages
  when the assistant replies: NKA's AI service and the language-model provider
  NKA uses, or the provider you chose with your own API key.
* External Services in this readme now lists NKA AI as a provider.

= 0.9.205 =

* The chat's texts and automatic replies now follow the language of the page
  the visitor is on. The widget sends the page language with every request,
  so suggestions and the takeover message match it too.
* Each conversation stores the language the visitor writes in. It shows in
  the Support Inbox list and conversation header, in the new-conversation
  email and in the personal data export. Detection can be turned off in
  Developer settings → Privacy and data.
* Added the `nkasupp_widget_texts` and `nkasupp_conversation_lang_detect`
  filters (see the FAQ).
* The AI no longer lists WooCommerce's default "Uncategorized" category or
  offers it as a filter. Products in it are still found. More categories can
  be hidden with the `nkasupp_hidden_product_categories` filter.

= 0.9.201 =

* Fixed AI answers that pointed to an article below ("no artigo abaixo") but
  showed no article card. The card now appears when the reply names an article
  found for that question, or when the model wrote the article reference into
  its text instead of citing it.

= 0.9.200 =

* Added an optional automatic deletion of conversations older than 3, 6, 12
  or 24 months. It is off by default.
* Conversations now appear in Tools → Export Personal Data and Erase Personal
  Data, matched by the visitor's email or WordPress account.
* Added suggested text for the site's privacy policy.
* Added an opt-in setting that removes the plugin's tables, settings,
  Knowledge Base files and scheduled tasks when the plugin is deleted. Off by
  default, so deleting the plugin keeps your data.
* Spam protection and privacy settings moved to a new Developer settings tab.
* Added a bar under the tabs to jump between the cards on each settings page.
* The Knowledge Base now offers only posts, pages and products for indexing.
* The Support Inbox shows the NKA credit balance from a button next to the
  Settings cog when replies use NKA AI.
* Other plugins' admin notices no longer appear on the plugin's pages.
* Plugin confirmation messages (such as "Settings saved") and the reindex
  warning, which were hidden by mistake, now appear.
* Fixed a doubled arrow on drop-down fields and a stray tick on disabled
  checkboxes in the admin screens.

= 0.9.11 =

* Team emails now work on sites without a connected NKA account: your team
  gets an email for each new conversation and when a visitor writes again
  after a reply. Each event can be turned off, a cooldown and an hourly cap
  prevent floods, and the recipient field accepts several addresses.
* Added spam protection for the public chat: per-IP limits on messages and on
  new conversations, a configurable maximum message length, and a choice of
  where the visitor IP address is read from. Inbox users are never limited.
* Messages over the length limit are now refused with a clear explanation
  instead of being cut off silently.

= 0.9.10 =

* Added Inbox access settings: choose which roles can read, answer, assign and
  delete conversations. By default administrators and WooCommerce Shop Managers
  can; Settings, Appearance and Knowledge Base stay administrator-only.
* The "Assigned to" list now shows only people who can open the inbox.

= 0.9.9 =

* Added the NKA AI provider: chat runs through the NKA AI gateway, with a
  credits panel (monthly allowance, extra credits and voucher redemption).
* Admin scripts now load the new build after an update instead of a cached copy.

= 0.9.8 =

* Fixed PhastPress compatibility: the widget's configuration is now excluded
  from script deferral, ensuring the saved colour, labels and position are
  available before the widget starts.

= 0.9.7 =

* Fixed the configuration globals sent to all four admin pages after the prefix
  migration. Portuguese translations, REST URLs and nonces now reach the React
  pages, including colour saves on sites without WordPress's API client loaded.
* Included the bundled Portuguese translations in release ZIPs so the widget and
  admin sidebar translate without a separately installed WordPress.org pack.

= 0.9.6 =

* All options, transients, scheduled hooks, post meta keys, global functions and
  admin page slugs now use a single `nkasupp` prefix. Sites upgrading from an
  earlier version are migrated automatically on first load: settings, indexing
  progress and uploaded Knowledge Base documents are carried over, and visitors
  keep access to the chats they already have open.
* Documented the source code and the build process for the compiled `dist/`
  assets in this readme.
* Rebuilt the translation template from the current source. It had drifted badly:
  47 interface strings were missing from it, so they could not be translated at
  all, and it still referenced files that had been deleted. Portuguese coverage
  goes from partial to 243 of 263 strings.
* Fixed two interface labels that were hard-coded in Portuguese instead of being
  translatable.
* Added "translators:" comments to every string containing a placeholder, so
  translators can tell what each `%s` and `%d` stands for.

= 0.9.5 =

* Initial submission to the WordPress Plugin Directory.
