=== Monoverse Sync ===
Contributors: monoverse
Tags: woocommerce, ai, chat, sales assistant, voice
Requires at least: 6.0
Tested up to: 6.7
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Syncs your WooCommerce catalog, pages and forms to Monoverse and adds its AI sales assistant, by voice and chat, to your store.

== Description ==

Monoverse Sync connects a WooCommerce store to Monoverse, an AI sales assistant that answers shoppers by voice and chat from the store's own catalog.

* **Catalog sync.** After pairing, the plugin sends products, variations, categories, tags, attributes, pages, menus, forms and popups to Monoverse, then each change as it happens.
* **The assistant on every page.** The plugin adds the Monoverse widget through `wp_footer`. It finds products, opens pages, fills in forms and adds to the cart for the shopper.
* **One key.** Paste your site's `pk_` key from Monoverse once: it connects both the sync and the widget.

= What is sent to Monoverse? =

Products, categories, tags, attributes, pages, blog posts (opt-in), navigation menus, site metadata (currency, store address) and an environment scan (theme, page builder, active plugins, languages, forms, popups). **Customer names, addresses, emails and other personal data are never collected. For each completed checkout the plugin sends only the order number, total, currency and status, plus the assistant's conversation stamp when one is present.**

= Supported integrations =

* Page builders: Gutenberg, Elementor, Divi, WPBakery
* SEO plugins: Yoast, RankMath, SEOPress, AIOSEO
* Form plugins: Contact Form 7, WPForms, Gravity Forms, Elementor Forms, Ninja Forms, Fluent Forms
* Popup plugins: Popup Maker, Elementor Pro Popups, OptinMonster, Convert Pro
* Multi-language: WPML, Polylang
* ACF (whitelisted fields)

== Installation ==

Upload, activate, paste your `pk_` from Monoverse → Integrations → your site → Install code.

1. In WordPress, open Plugins → Add New → Upload Plugin, upload `monoverse-sync.zip` and activate Monoverse Sync. WooCommerce 7.0 or later must be active.
2. In Monoverse, open Integrations → your site → Install code and copy the `pk_` key.
3. In WordPress, open Monoverse Sync → Connection, paste the key and save. The first full sync starts once Monoverse has checked that the site answers on the key's domain.

= Upgrading from VoiceBot Sync =

Upload and activate Monoverse Sync while VoiceBot Sync is still active. On the next admin page Monoverse Sync deactivates VoiceBot Sync and keeps its connection, settings and queue, so you do not pair again. Then delete VoiceBot Sync from the Plugins screen: Monoverse Sync keeps using its data.

== Frequently Asked Questions ==

= Where do I get the pk_ key? =

In Monoverse, under Integrations → your site → Install code. The same key connects the catalog sync and the assistant.

= Can I turn the widget off and keep the sync? =

Yes. Monoverse Sync → Widget → clear "Enable widget".

= Does the plugin slow my store down? =

No page load waits on Monoverse: changes are queued and sent in the background through Action Scheduler, and the widget script loads asynchronously.

= How do I remove everything? =

Tick "Delete data on uninstall" under Monoverse Sync → Privacy, then deactivate and delete the plugin. Without the tick the connection and settings stay for a reinstall.

== External services ==

This plugin connects your store to Monoverse at `api.monoverse.tech`.

* **Pairing.** When you save your `pk_` key, the plugin sends the key, the site address, its locale and time zone, the WordPress, WooCommerce, PHP and plugin versions and the detected theme and plugins to `https://api.monoverse.tech/api/v1/ingest/pair-by-key`. Monoverse then checks once, over HTTPS, that the site answers on the key's domain.
* **Catalog sync.** After pairing, the plugin sends the data listed under "What is sent to Monoverse?" to `https://api.monoverse.tech/api/v1/ingest/` over HMAC-signed HTTPS: a full snapshot, then each change, a status check every 15 minutes, and once per plugin version the paths it serves. Monoverse calls those paths back, signed with the same key, to ask for a fresh sync, to submit a form a shopper filled in through the assistant, or to read the site's structure.
* **Widget script.** On every storefront page where the widget is enabled, the visitor's browser loads the widget from `https://api.monoverse.tech/widget/widget-voice.js` and its audio worklet from the same directory. That address serves the latest widget release, which `https://api.monoverse.tech/widget/latest.json` names. To freeze one release, enter its `https://api.monoverse.tech/widget/v/<id>/widget-voice.js` address under Monoverse Sync → Widget, or define `MONOVERSE_SYNC_WIDGET_URL` in `wp-config.php`. The last 20 releases stay available.
* **Conversation.** While a visitor talks to the assistant, the widget sends their chat messages, their voice while the microphone is on, the address of the page they are on and the contents of their cart to `api.monoverse.tech`, and plays back the assistant's answers.
* **cdn.jsdelivr.net.** The widget loads the ThumbmarkJS script from `https://cdn.jsdelivr.net` only when its trust fingerprint is turned on through the `data-trust-fingerprint` attribute, which this plugin never sets.

Terms of service: https://monoverse.tech/en/legal/offer
Privacy policy: https://monoverse.tech/en/legal/privacy

== Changelog ==

= 1.0.0 =
* VoiceBot Sync is now Monoverse Sync: the plugin name, its folder and slug `monoverse-sync`, the text domain, the PHP namespace `Monoverse\Sync`, the `MONOVERSE_SYNC_*` constants, the `monoverse_sync_*` hooks and the REST namespace `monoverse-sync/v1`.
* Installed beside VoiceBot Sync, Monoverse Sync deactivates it on the next admin page and keeps its connection: options, tables, scheduled actions and the stored key keep their names, and VoiceBot Sync's "Delete data on uninstall" choice moves to Monoverse Sync, so deleting VoiceBot Sync removes nothing.
* Until 2027-04-30 the plugin also answers under `voicebot-sync/v1` and honours the `VOICEBOT_SYNC_*` constants and the `voicebot_sync_*` hooks, with a deprecation notice.
* The plugin tells Monoverse which callback and inventory paths it serves, once per version.
* Requests carry `X-Monoverse-*` headers.
* The plugin's own updater is gone: updates come from wordpress.org once the plugin is listed there, and from the Monoverse cabinet until then.

= 0.7.1 =
* Cart snapshot answers only the shop's own pages. `GET
  /wp-json/voicebot-sync/v1/cart-snapshot` requires the REST nonce the bridge
  hands the widget, sent in `X-WP-Nonce`, and refuses a foreign `Origin` or a
  cross-site `Sec-Fetch-Site` with `403` before it reads the cart. It loads the
  visitor's WooCommerce cart itself, answers `Cache-Control: no-store, private`
  and no longer returns the WooCommerce session key.
* Catalog deltas carry the shop's state at the moment they are sent. A
  product that is published or private and has no post password is sent in
  full, whatever its catalog visibility; a draft, pending, scheduled, trashed,
  deleted or password-protected product is sent as a delete of its id and of
  its variations' ids. A disabled variation leaves the product's variation
  list and is deleted, and a category or tag that no longer exists is deleted.
* Product and category deltas of a WPML or Polylang translation name the
  default-language original in `translation_of`.
* A queued change stays queued until its send is handled. A failed send
  retries with backoff and re-reads the current state, a change made during a
  send goes out with the next one, and a flush that finds nothing due
  schedules the next one. Flushes no longer overlap.
* Ops the backend rejects in a successful response are parked by reference
  and replayed at most three times; any later successful send clears them.
  Each flush writes one line to the WooCommerce log.
* Environment, form and popup ops travel in their own request.
* Nothing is queued while the plugin is unpaired, and pairing again restores
  the heartbeat.
* Database tables and recurring actions are brought up to date on the first
  page load after an update, not only on activation.
* The Status tab and `/diagnostics` show the age of the oldest queued change
  and the parked refs.

= 0.7.0 — 2026-10-02 =
* Pair challenge: pairing by store key (pk_…) now proves that this site
  controls the key's domain. The plugin sends a one-time `pair_nonce` with the
  key, and the new public REST route
  `GET /wp-json/voicebot-sync/v1/pair-challenge?challenge=…` answers the
  backend with `{"proof": HMAC-SHA256(challenge, nonce)}` while that pairing is
  in progress, and `404 no_pairing_in_progress` otherwise, always with
  `Cache-Control: no-store`. The nonce lives in a 10-minute transient and is
  deleted as soon as the pair call returns. The site must answer over HTTPS at
  the domain root; a site installed below the root, behind a plugin that blocks
  the REST API, or on a single PHP worker pairs with a cabinet pair-code
  instead.
* Order event at checkout: one `order` entity per completed checkout, classic
  and block checkout alike, carrying the order number, total, currency and
  status, plus the widget conversation id from the stamped `vb_conversation`
  cookie, so a sale can be attributed to the conversation that led to it. No
  customer name, address, email or line items are sent.
* Remote sync trigger: an HMAC-signed `POST /wp-json/voicebot-sync/v1/sync`
  lets the backend queue a full or delta sync through Action Scheduler.
* Pairing declares `source_package = woocommerce_wp` on both pair paths.
* The protocol declares only the entity kinds the backend projector accepts.

= 0.6.1 — 2026-06-19 =
* Pairing now declares `provider_id = woocommerce` and the detected stack
  (`technologies`, e.g. the active theme) so the backend records the real
  platform of the store instead of a default.

= 0.6.0 — 2026-06-19 =
* Pair-by-key: paste a single store key (pk_…) to drive both catalog-sync
  pairing and widget injection. The plugin now pairs via
  `POST /api/v1/ingest/pair-by-key` ({public_key, site_url, …}) and stores the
  key in `voicebot_sync_public_key`. The legacy one-time pair-code path still
  works server-side for already-paired installs; their stored shared secret
  keeps signing catalog sync unchanged.
* Widget loader now emits `data-public-key` instead of `data-tenant-token`.
  Removed the widget-JWT issue-token machinery (`Token_Issuer`, the 25-minute
  refresh job, and the `data-tenant-token` fallback) entirely.
* Graceful migration: an install paired via the old pair-code that has no
  store key yet skips widget injection and shows an admin notice prompting the
  merchant to enter their pk_, instead of rendering a broken widget.

= 0.5.0 — 2026-05-12 =
* F-206: Landing_Classifier для розпізнавання сторінок-категорій (Elementor/Divi/тема).
* F-206: Menu_Collector emit-per-item з link_kind classification.
* F-206: +10 theme adapters (Woodmart/Porto/XStore/Shopkeeper/Electro/Hongo/Basel/TheGem/The7/Bridge).
* F-206: REST endpoints /sil/forms та /sil/buttons (HMAC).
* F-206: Розширений Wc_Virtual_Pages allowlist (18 endpoints).
* F-206: formMap + buttonsAllowlist inline у widget bridge.
* Page_Collector: нові поля intent_kind, landing_kind, landing_confidence, aliases, curated_products.

= 0.3.0 =
* Widget auth: plugin now exchanges its HMAC-signed identity for a
  short-lived widget JWT via `POST /api/v1/widget/issue-token`. The
  `data-tenant-token` attribute on the loader script tag is therefore a
  real token instead of a raw tenant UUID, so the widget WS handshake no
  longer falls through to the legacy uuid-token path on the backend.
  Refresh runs every 25 minutes (Action Scheduler), with a one-shot
  refresh scheduled immediately after pairing. The cached token lives in
  `voicebot_sync_widget_token` (autoload disabled) and is wiped on
  unpair / uninstall (when the merchant opts in to data deletion). A
  diagnostics row in the admin Diagnostics tab surfaces token expiry so
  support can spot a stale cache from outside the site.

= 0.2.0 =
* Site Intelligence Layer (SIL): new HMAC-authenticated read-only endpoint
  `GET /wp-json/voicebot-sync/v1/sil/snapshot` exposes the merged output of
  the environment, site, CPT auto-discover, taxonomy, WC virtual-page, and
  per-page block-map collectors so the backend can route conversational
  intents without a separate full-sync pull. Block map is capped to the 200
  most recently modified pages/posts plus the well-known WC pages
  (shop/cart/checkout/myaccount/terms); raise via the
  `voicebot_sync_sil_block_map_cap` filter. No-op on read; never includes
  customer data.

= 0.1.7 =
* Backend: lazy orphan-slot cleanup. When the per-tenant active-session set
  hits its limit, the anchor now scans up to 20 entries and evicts ones
  whose Redis state no longer exists OR whose widget disconnected longer
  than 2x the grace window ago, before raising the limit error. Prevents
  ghost sessions accumulated by reconnect loops or browser-close-without-
  end events from blocking new connections for 24 h.

= 0.1.6 =
* Backend: when a Gemini Live session fails to open (missing key, retired
  model, quota), close the WebSocket with code 4503 (fatal) instead of 1000
  (transient). The widget previously interpreted 1000 as "lost connection,
  please retry" and looped forever. The error event ("voice_unavailable")
  is also marked non-retryable so the widget shows a clear banner instead
  of a silent reconnect spinner.
* Widget: safety-net circuit-breaker — after 5 connections in a row that
  close without ever exchanging a single message, the widget gives up and
  surfaces a fatal-state banner. Catches every cause we don't explicitly
  classify (network blocks, server crashes during accept, etc).
* Widget: the "voice_unavailable" server error now triggers the same fatal
  UI path as auth_failed (banner, no further reconnect attempts).

= 0.1.5 =
* Critical reconnect-loop fix: widget no longer infinitely retries on fatal
  close codes (4401 invalid token, 4403 origin not allowed, 4503 voice
  provider down, 1008 session limit, 1011 server crash). Instead it shows
  a clear, actionable error banner and stops hammering the backend.
* Backend: WS close codes now carry a `reason` string the browser can read
  (was: bare numeric code). Auth/origin/tenant errors are logged with
  full diagnostic context (origin, tenant_id, token prefix).

= 0.1.4 =
* Widget UI redesigned to match the public demo: chat-history bubbles take
  centre stage, the giant "Выключить микрофон" button is replaced with a
  compact 36px mic toggle in the footer next to a text input + send button.
* Reconnect UX fix: a fresh page no longer flashes "Перепідключаємось…"
  before the first WS connect. Until at least one successful connection has
  happened, status reads "Підключаємось…"; only post-disconnect retries
  surface the "Перепідключаємось…" copy.
* All status labels in the header are now Ukrainian-locked even on
  Russian-detected browsers (per Ukraine-first product policy).

= 0.1.3 =
* Theme-aware cart drawer: Astra, Flatsome, OceanWP, Hello/Elementor, Kadence
  cart sidebars now open after the bot adds a product (was: silent fragment
  refresh only). Falls back to canonical `added_to_cart` jQuery event.
* window.VoiceBotSyncBridge gains openMiniCart / openMobileMenu / openSearch /
  openAccount methods + themeCapabilities flag map. Widget detects what the
  active theme can do without site-by-site config.

= 0.1.2 =
* Backend: re-applies the latest system_instruction on session reattach so
  prompt updates (e.g. [SYSTEM_NAVIGATION] handling) propagate to existing
  Redis sessions instead of using the stale instruction frozen at create-time.
* Widget: rich console logging on every navigation/resume decision (enable
  with `localStorage.setItem('voicebot_debug','1')` then refresh).
* Widget: cache-busting query string on the bundle URL — bumping plugin
  version or rebuilding the widget now invalidates browser/CDN caches.

= 0.1.1 =
* Widget: bot now announces page navigation after a session resume — short
  one-liner like «Я з вами на сторінці контактів» plays automatically when
  the customer changes pages while in a voice conversation.
* Widget: desktop voice now auto-resumes after page reload (no need to tap
  the mic button); iOS Safari still requires a tap because of OS gesture
  policy.
* Widget bundle refreshed (voice 25.49 KB gzip, chat 23.75 KB gzip).
* No PHP-side changes — drop-in update.

= 0.1.0 =
* Initial scaffold release.

== Upgrade Notice ==

= 1.0.0 =
VoiceBot Sync becomes Monoverse Sync. Upload and activate Monoverse Sync while VoiceBot Sync is active: it takes over the connection. Then delete VoiceBot Sync.

= 0.7.0 =
Required to pair by store key: the backend now asks the site to prove it controls the key's domain, and 0.7.0 is the first version that answers that challenge.

= 0.6.0 =
One store key (pk_…) now connects both catalog sync and the widget. After upgrading, paste your store key under VoiceBot Sync → Connection to enable the on-site assistant.

= 0.3.0 =
Plugin now obtains a short-lived widget JWT from the backend instead of emitting the raw tenant UUID. Required to keep the widget connecting after the legacy fallback path is retired.

= 0.2.0 =
Adds the read-only SIL snapshot endpoint used by the backend SIL router. Additive change; existing endpoints unchanged.

= 0.1.7 =
Self-healing for ghost voice sessions; recommended after upgrading from <= 0.1.5.

= 0.1.6 =
Critical: definitively stops the reconnect loop and shows the actual cause (likely Gemini Live config).

= 0.1.5 =
Critical: stops the perpetual "Перепідключаємось…" loop and shows the actual cause.

= 0.1.4 =
Widget UI overhaul: chat history is now the focus, mic mute is a small icon. Reconnect-loop visual artefact fixed.

= 0.1.3 =
Cart drawer now opens after bot adds to cart (previously required page reload).

= 0.1.2 =
Critical fix for session reattach + cache-busting + diagnostic logging. Recommended.

= 0.1.1 =
Refreshed widget bundle: bot acknowledges page navigation and desktop voice auto-resumes after reload.

= 0.1.0 =
Initial release.
