PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 3.2.25
MxChat – AI Chatbot & Content Generation for WordPress v3.2.25
3.2.25 3.2.24 3.2.23 3.2.22 3.2.21 3.2.20 3.2.19 3.2.18 3.2.17 3.2.16 3.2.15 3.2.14 3.2.12 3.2.13 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 3.2.6 3.2.5 3.2.4 3.2.3 3.2.2 3.2.1 All 156 releases
← All changes | includes/admin-knowledge-page.php +313 -35 3.2.20 → 3.2.25 View file →
@@ -283,8 +283,27 @@
283 283 mxchat_render_knowledge_page_scripts();
284 284 }
285 285
286 286 /**
287 + * Whether the selected bot answers from the WordPress database (plan 1f39d9).
288 + * That store is one table every bot reads. A bot has knowledge of its own only
289 + * on Pinecone (its own host or namespace) or an OpenAI Vector Store, so the
290 + * selector must not promise a per-bot knowledge base here.
291 + */
292 +function mxchat_knowledge_bot_uses_shared_database($bot_id) {
293 + $pinecone = class_exists('MxChat_Pinecone_Documents') ? MxChat_Pinecone_Documents::config($bot_id) : array();
294 + if (!empty($pinecone['use_pinecone'])) {
295 + return false;
296 + }
297 + $vectorstore_options = get_option('mxchat_openai_vectorstore_options', array());
298 + $vectorstore = apply_filters('mxchat_get_bot_vectorstore_config', array(
299 + 'use_vectorstore' => (is_array($vectorstore_options) ? ($vectorstore_options['mxchat_use_openai_vectorstore'] ?? '0') : '0') === '1',
300 + 'vectorstore_ids' => is_array($vectorstore_options) ? ($vectorstore_options['mxchat_vectorstore_ids'] ?? '') : '',
301 + ), $bot_id);
302 + return empty($vectorstore['use_vectorstore']);
303 +}
304 +
305 +/**
287 306 * Render Multi-Bot Selector
288 307 */
289 308 function mxchat_render_knowledge_bot_selector($multibot_active, $current_bot_id) {
290 309 if (!$multibot_active || !class_exists('MxChat_Multi_Bot_Manager')) {
@@ -307,9 +326,15 @@
307 326 </option>
308 327 <?php endforeach; ?>
309 328 </select>
310 329 <span style="color: var(--mxch-text-secondary); font-size: 13px;">
311 - <?php esc_html_e('Content will be added to the selected bot\'s knowledge base', 'mxchat'); ?>
330 + <?php
331 + if (mxchat_knowledge_bot_uses_shared_database($current_bot_id)) {
332 + esc_html_e('This bot answers from the WordPress database, which is shared with all bots: content added here is available to every bot that uses it. A bot gets a knowledge base of its own on Pinecone (its own host or namespace) or an OpenAI Vector Store.', 'mxchat');
333 + } else {
334 + esc_html_e('Content will be added to the selected bot\'s knowledge base', 'mxchat');
335 + }
336 + ?>
312 337 </span>
313 338 <span id="mxchat-bot-save-status" style="display: none; color: var(--mxch-success); font-size: 13px;">
314 339 ✓ <?php esc_html_e('Saved', 'mxchat'); ?>
315 340 </span>
@@ -439,8 +464,20 @@
439 464 $required_key_type = 'Voyage AI';
440 465 } elseif (strpos($embedding_model, 'gemini-embedding-') !== false) {
441 466 $required_key_type = 'Google Gemini';
442 467 }
468 +
469 + // Custom Provider embeddings (plan 418afd): the dropdown above is disabled
470 + // on such a site and no OpenAI, Voyage or Gemini key is needed. Ask the
471 + // same pre-flight the importers ask, so this notice cannot disagree with them.
472 + $embeds_with_custom_provider = is_array($options) && isset($options['custom_provider_for_embeddings']) && $options['custom_provider_for_embeddings'] === 'on';
473 + $custom_embedding_blocker = '';
474 + if ($embeds_with_custom_provider) {
475 + $custom_preflight = MxChat_Utils::embedding_preflight($options);
476 + $has_required_key = !empty($custom_preflight['ok']);
477 + $required_key_type = 'Custom Provider';
478 + $custom_embedding_blocker = (string) ($custom_preflight['reason'] ?? '');
479 + }
443 480 ?>
444 481 <div id="import-options" class="mxch-section active">
445 482 <div class="mxch-content-header">
446 483 <h1 class="mxch-content-title"><?php esc_html_e('Import Options', 'mxchat'); ?></h1>
@@ -456,9 +493,18 @@
456 493 <path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/>
457 494 <?php endif; ?>
458 495 </svg>
459 496 <div>
460 - <?php if ($has_required_key): ?>
497 + <?php if ($embeds_with_custom_provider && $has_required_key): ?>
498 + <?php
499 + /* translators: %s: the embedding model name configured on the Custom Provider */
500 + printf(esc_html__('Knowledge is embedded through your Custom Provider (model: %s). No OpenAI, Voyage AI or Google Gemini key is needed for imports.', 'mxchat'), esc_html(MxChat_Utils::resolve_custom_embedding_model($options)));
501 + ?>
502 + <?php elseif ($embeds_with_custom_provider): ?>
503 + <strong><?php esc_html_e('Important:', 'mxchat'); ?></strong>
504 + <?php echo esc_html($custom_embedding_blocker); ?>
505 + <a href="<?php echo admin_url('admin.php?page=mxchat-max#api-keys'); ?>"><?php esc_html_e('Go to API Key Settings', 'mxchat'); ?></a>
506 + <?php elseif ($has_required_key): ?>
461 507 <?php echo wp_kses_post(sprintf(__('We detected your %s API key. <strong>Remember to add credits to your %s account</strong> before using the knowledgebase.', 'mxchat'), $required_key_type, $required_key_type)); ?>
462 508 <?php else: ?>
463 509 <strong><?php esc_html_e('Important:', 'mxchat'); ?></strong>
464 510 <?php echo sprintf(esc_html__('Before importing knowledge, you must add a %s API key with sufficient credits in the Chatbot settings.', 'mxchat'), $required_key_type); ?>
@@ -675,8 +721,14 @@
675 721 </div>
676 722 <p class="mxch-field-description">
677 723 <?php esc_html_e('Select a PDF file from your computer to import into the knowledge base. Maximum file size depends on your server settings.', 'mxchat'); ?>
678 724 </p>
725 + <div class="mxch-field">
726 + <input type="url" name="source_page_url" id="mxchat-pdf-source-url" class="mxch-input" placeholder="<?php esc_attr_e('Enter source URL (Optional)', 'mxchat'); ?>">
727 + <p class="mxch-field-description">
728 + <?php esc_html_e('The page this PDF lives on. Answers drawn from it link to that page. Leave empty and answers name the file and page without a link.', 'mxchat'); ?>
729 + </p>
730 + </div>
679 731 <button type="submit" name="submit_pdf_file" class="mxch-btn mxch-btn-primary">
680 732 <?php esc_html_e('Import PDF', 'mxchat'); ?>
681 733 </button>
682 734 </form>
@@ -693,8 +745,14 @@
693 745 </div>
694 746 <p class="mxch-field-description">
695 747 <?php esc_html_e('Select a .docx, .txt, or .md file to import into the knowledge base. The text is extracted and indexed; the file itself is not stored. Re-uploading a file with the same name replaces its previous content.', 'mxchat'); ?>
696 748 </p>
749 + <div class="mxch-field">
750 + <input type="url" name="source_page_url" id="mxchat-document-source-url" class="mxch-input" placeholder="<?php esc_attr_e('Enter source URL (Optional)', 'mxchat'); ?>">
751 + <p class="mxch-field-description">
752 + <?php esc_html_e('The page this document lives on. Answers drawn from it link to that page. Leave empty and answers name the file without a link.', 'mxchat'); ?>
753 + </p>
754 + </div>
697 755 <button type="submit" name="submit_document_file" class="mxch-btn mxch-btn-primary">
698 756 <?php esc_html_e('Import Document', 'mxchat'); ?>
699 757 </button>
700 758 </form>
@@ -896,9 +954,10 @@
896 954 <div class="mxch-card">
897 955 <div class="mxch-card-header">
898 956 <h3 class="mxch-card-title">
899 957 <?php esc_html_e('Knowledge Entries', 'mxchat'); ?>
900 - <span id="mxchat-entry-count" style="font-weight: normal; color: var(--mxch-text-secondary);">(<?php echo esc_html($total_records); ?>)</span>
958 + <?php $count_unit = $count_unit ?? ''; ?>
959 + <span id="mxchat-entry-count" style="font-weight: normal; color: var(--mxch-text-secondary);" data-count="<?php echo esc_attr($total_records); ?>" data-unit="<?php echo esc_attr($count_unit); ?>"<?php if ($count_unit === 'vectors') : ?> title="<?php esc_attr_e('Pinecone reports vectors, not documents; a long entry is stored as several vectors.', 'mxchat'); ?>"<?php endif; ?>>(<?php echo esc_html(number_format_i18n($total_records)); ?><?php if ($count_unit === 'vectors') : ?> <?php esc_html_e('vectors', 'mxchat'); ?><?php endif; ?>)</span>
901 960 <?php if (!empty($use_vectorstore)) : ?>
902 961 <span style="display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border-radius: 12px; font-size: 12px; font-weight: 500; margin-left: 8px; background: #fff3e0; color: #e65100;">
903 962 <span class="dashicons dashicons-database" style="font-size: 14px;"></span>
904 963 <?php esc_html_e('Not in use', 'mxchat'); ?>
@@ -1068,16 +1127,9 @@
1068 1127 </span>
1069 1128 </div>
1070 1129 </td>
1071 1130 <td class="mxchat-url-cell" style="padding: 12px 16px; font-size: 13px;">
1072 - <?php if (!empty($source_url) && strpos($source_url, 'mxchat://') !== 0 && strpos($source_url, '_ungrouped_') !== 0) : ?>
1073 - <a href="<?php echo esc_url($source_url); ?>" target="_blank" style="color: var(--mxch-primary); text-decoration: none;">
1074 - <span class="dashicons dashicons-external" style="font-size: 14px;"></span>
1075 - <?php esc_html_e('View Source', 'mxchat'); ?>
1076 - </a>
1077 - <?php else : ?>
1078 - <span style="color: var(--mxch-text-muted);"><?php esc_html_e('Manual Content', 'mxchat'); ?></span>
1079 - <?php endif; ?>
1131 + <?php echo MxChat_Knowledge_Manager::mxchat_source_cell_html($source_url, $current_bot_id, true); ?>
1080 1132 </td>
1081 1133 <td class="mxchat-actions-cell" style="padding: 12px 16px; white-space: nowrap;">
1082 1134 <button type="button"
1083 1135 class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-inspect-entry-btn"
@@ -1226,16 +1278,10 @@
1226 1278 $actual_source = $source_url;
1227 1279 if (strpos($source_url, '_ungrouped_') === 0) {
1228 1280 $actual_source = $prompt->source_url ?? '';
1229 1281 }
1230 - if (!empty($actual_source) && strpos($actual_source, 'mxchat://') !== 0) : ?>
1231 - <a href="<?php echo esc_url($actual_source); ?>" target="_blank" style="color: var(--mxch-primary); text-decoration: none;">
1232 - <span class="dashicons dashicons-external" style="font-size: 14px;"></span>
1233 - <?php esc_html_e('View', 'mxchat'); ?>
1234 - </a>
1235 - <?php else : ?>
1236 - <span style="color: var(--mxch-text-muted);"><?php esc_html_e('Manual', 'mxchat'); ?></span>
1237 - <?php endif; ?>
1282 + echo MxChat_Knowledge_Manager::mxchat_source_cell_html($actual_source, $current_bot_id, false);
1283 + ?>
1238 1284 </td>
1239 1285 <td style="padding: 12px 16px; white-space: nowrap;">
1240 1286 <button type="button"
1241 1287 class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-inspect-entry-btn"
@@ -1275,10 +1321,21 @@
1275 1321 </table>
1276 1322 </div>
1277 1323
1278 1324 <!-- Pagination wrapper - always present so JS can populate it after processing -->
1279 - <div id="mxchat-kb-pagination" class="mxchat-kb-pagination-wrapper" style="<?php echo $total_pages > 1 ? 'padding: 16px; border-top: 1px solid var(--mxch-card-border); text-align: center;' : ''; ?>" data-current-page="<?php echo esc_attr($current_page); ?>" data-total-pages="<?php echo esc_attr($total_pages); ?>" data-search="<?php echo esc_attr($search_query); ?>" data-content-type="<?php echo esc_attr($content_type_filter); ?>">
1280 - <?php if ($total_pages > 1) : ?>
1325 + <?php
1326 + // Plan dd6e10: Pinecone's list endpoint is a cursor — there is no
1327 + // random access to page N, so over 500 vectors the screen offers
1328 + // Previous / Next only. The same markup is built for AJAX page
1329 + // loads by MxChat_Knowledge_Manager::mxchat_cursor_pagination_html().
1330 + $cursor_pagination = !empty($cursor_pagination);
1331 + $has_next = !empty($has_next);
1332 + $show_pagination = $cursor_pagination ? ($current_page > 1 || $has_next) : ($total_pages > 1);
1333 + ?>
1334 + <div id="mxchat-kb-pagination" class="mxchat-kb-pagination-wrapper" style="<?php echo $show_pagination ? 'padding: 16px; border-top: 1px solid var(--mxch-card-border); text-align: center;' : ''; ?>" data-current-page="<?php echo esc_attr($current_page); ?>" data-total-pages="<?php echo esc_attr($total_pages); ?>" data-search="<?php echo esc_attr($search_query); ?>" data-content-type="<?php echo esc_attr($content_type_filter); ?>">
1335 + <?php if ($cursor_pagination) : ?>
1336 + <?php echo MxChat_Knowledge_Manager::mxchat_cursor_pagination_html($current_page, $has_next, $search_query, $content_type_filter); // phpcs:ignore WordPress.Security.EscapeOutput -- escaped inside ?>
1337 + <?php elseif ($total_pages > 1) : ?>
1281 1338 <div class="mxchat-ajax-pagination" data-current-page="<?php echo esc_attr($current_page); ?>" data-total-pages="<?php echo esc_attr($total_pages); ?>">
1282 1339 <?php if ($current_page > 1) : ?>
1283 1340 <a href="#" class="mxchat-page-link" data-page="<?php echo ($current_page - 1); ?>"><?php esc_html_e('&laquo; Previous', 'mxchat'); ?></a>
1284 1341 <?php endif; ?>
@@ -1317,13 +1374,97 @@
1317 1374 <?php endif; ?>
1318 1375 </div>
1319 1376 </div>
1320 1377 </div>
1378 +
1379 + <?php mxchat_render_kb_reimport_card(!empty($current_bot_id) ? $current_bot_id : 'default'); ?>
1321 1380 </div>
1322 1381 <?php
1323 1382 }
1324 1383
1325 1384 /**
1385 + * "Re-import affected entries" card (plan 89739b).
1386 + *
1387 + * The owner-facing side of wp mxchat kb-reimport: check first (no embedding
1388 + * request, nothing written), read the list, then confirm. Both halves run in
1389 + * resumable steps through the mxchat_kb_reimport AJAX action; the script is
1390 + * js/knowledge-reimport.js. Everything dynamic is drawn there; this is the
1391 + * resting markup.
1392 + */
1393 +function mxchat_render_kb_reimport_card($current_bot_id = 'default') {
1394 + if (!class_exists('MxChat_Knowledge_Manager')) {
1395 + return;
1396 + }
1397 + ?>
1398 + <div class="mxch-card mxch-kb-reimport" id="mxchat-kb-reimport"
1399 + data-nonce="<?php echo esc_attr(wp_create_nonce('mxchat_kb_reimport')); ?>"
1400 + data-bot="<?php echo esc_attr($current_bot_id); ?>">
1401 + <div class="mxch-card-header">
1402 + <h3 class="mxch-card-title">
1403 + <svg class="mxch-card-title-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><polyline points="1 20 1 14 7 14"/><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"/></svg>
1404 + <?php esc_html_e('Re-import affected entries', 'mxchat'); ?>
1405 + </h3>
1406 + </div>
1407 + <div class="mxch-card-body">
1408 + <p class="mxch-field-description"><?php esc_html_e('Earlier versions stored some imported text incorrectly: currency signs and accents were dropped, HTML character codes were left in, and right-to-left PDF text was saved backwards. This finds the entries that still hold that text and rebuilds them from their source. Checking changes nothing.', 'mxchat'); ?></p>
1409 +
1410 + <div class="mxch-kb-reimport-controls">
1411 + <div class="mxch-field">
1412 + <label class="mxch-field-label" for="mxchat-kb-reimport-before"><?php esc_html_e('Entries last written before', 'mxchat'); ?></label>
1413 + <input type="date" id="mxchat-kb-reimport-before" class="mxch-input mxch-input-sm" value="<?php echo esc_attr(MxChat_Knowledge_Manager::REIMPORT_DEFAULT_BEFORE); ?>" max="<?php echo esc_attr(gmdate('Y-m-d', time() + DAY_IN_SECONDS)); ?>" />
1414 + </div>
1415 + <button type="button" class="mxch-btn mxch-btn-secondary" id="mxchat-kb-reimport-check"><?php esc_html_e('Check knowledge base', 'mxchat'); ?></button>
1416 + </div>
1417 + <p class="mxch-field-hint"><?php esc_html_e('The date is the release that carried the last of these fixes. Choose a later one if this site was updated after that.', 'mxchat'); ?></p>
1418 +
1419 + <!-- Also offer entries whose page was edited after they were imported (plan a00ef8); off by default -->
1420 + <div class="mxch-field mxch-kb-reimport-edited">
1421 + <label class="toggle-switch">
1422 + <input type="checkbox" id="mxchat-kb-reimport-edited" name="mxchat_kb_reimport_edited" value="1" />
1423 + <span class="slider"></span>
1424 + </label>
1425 + <div class="mxch-kb-reimport-edited-text">
1426 + <label class="mxch-field-label" for="mxchat-kb-reimport-edited"><?php esc_html_e('Also rewrite entries whose page was edited after they were imported', 'mxchat'); ?></label>
1427 + <p class="mxch-field-description"><?php esc_html_e('An entry older than its post, page, product or media file is rebuilt from it as it reads today. A site with auto-sync on does not need this.', 'mxchat'); ?></p>
1428 + </div>
1429 + </div>
1430 +
1431 + <div class="mxch-kb-reimport-progress" hidden>
1432 + <div class="mxch-progress-bar" hidden><div class="mxch-progress-bar-fill"></div></div>
1433 + <p class="mxch-progress-label" aria-live="polite"></p>
1434 + </div>
1435 +
1436 + <div class="mxch-notice mxch-notice-error mxch-kb-reimport-error" role="alert" hidden>
1437 + <svg class="mxch-notice-icon" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>
1438 + <span></span>
1439 + </div>
1440 +
1441 + <div class="mxch-kb-reimport-results" hidden>
1442 + <div class="mxch-notice mxch-notice-success mxch-kb-reimport-done" hidden>
1443 + <svg class="mxch-notice-icon" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
1444 + <span></span>
1445 + </div>
1446 + <div class="mxch-kb-reimport-counts"></div>
1447 + <ul class="mxch-kb-reimport-list mxch-kb-reimport-entries" hidden></ul>
1448 + <p class="mxch-field-hint mxch-kb-reimport-more" hidden></p>
1449 + <details class="mxch-disclosure mxch-kb-reimport-others" hidden>
1450 + <summary class="mxch-disclosure-summary"><span class="mxch-disclosure-summary-text"></span><span class="mxch-disclosure-summary-hint"><?php esc_html_e('Never changed or removed by this tool', 'mxchat'); ?></span></summary>
1451 + <div class="mxch-disclosure-body">
1452 + <ul class="mxch-kb-reimport-list mxch-kb-reimport-notes"></ul>
1453 + </div>
1454 + </details>
1455 + </div>
1456 + </div>
1457 + <div class="mxch-card-footer mxch-kb-reimport-footer" hidden>
1458 + <button type="button" class="mxch-btn mxch-btn-primary" id="mxchat-kb-reimport-apply"></button>
1459 + <button type="button" class="mxch-btn mxch-btn-ghost" id="mxchat-kb-reimport-clear"><?php esc_html_e('Clear', 'mxchat'); ?></button>
1460 + <span class="mxch-field-hint mxch-kb-reimport-cost"><?php esc_html_e('Each rewritten entry is embedded again with your embedding provider.', 'mxchat'); ?></span>
1461 + </div>
1462 + </div>
1463 + <?php
1464 +}
1465 +
1466 +/**
1326 1467 * Render Auto-Sync Section
1327 1468 */
1328 1469 function mxchat_render_auto_sync_section($knowledge_manager) {
1329 1470 ?>
@@ -1459,12 +1600,12 @@
1459 1600 <label class="mxchat-toggle-switch">
1460 1601 <input type="checkbox" name="mxchat_hybrid_keyword_toggle" id="mxchat_hybrid_keyword_toggle" class="mxchat-autosave-field" value="on" <?php checked(get_option('mxchat_hybrid_keyword_toggle', 'off'), 'on'); ?>>
1461 1602 <span class="mxchat-toggle-slider"></span>
1462 1603 </label>
1463 - <span style="font-weight: 500;"><?php esc_html_e('Hybrid keyword boost (WP-DB knowledge base)', 'mxchat'); ?></span>
1604 + <span style="font-weight: 500;"><?php esc_html_e('Hybrid keyword boost (WordPress database and Pinecone document indexes)', 'mxchat'); ?></span>
1464 1605 </div>
1465 - <p class="mxch-field-description" style="margin-top: 8px;"><?php esc_html_e('Combines keyword matching with vector similarity when searching your WordPress-database knowledge base. Helps exact-token questions — product codes, SKUs, error codes, names — find the right document even when semantic similarity alone would miss it.', 'mxchat'); ?></p>
1466 - <p class="mxch-field-hint"><?php esc_html_e('Only affects the WordPress-database knowledge base; Pinecone is unaffected. Changes which sources are retrieved on existing installs, so test after enabling. The Transcripts sources panel labels how each match was found while this is on.', 'mxchat'); ?></p>
1606 + <p class="mxch-field-description" style="margin-top: 8px;"><?php esc_html_e('Combines keyword matching with vector similarity when searching your WordPress-database knowledge base or a Pinecone document index. Helps exact-token questions — product codes, SKUs, error codes, names — find the right document even when semantic similarity alone would miss it.', 'mxchat'); ?></p>
1607 + <p class="mxch-field-hint"><?php esc_html_e('Applies to the WordPress-database knowledge base and to Pinecone when the index type is Document index with full-text search; a classic Pinecone vector index is unaffected. Changes which sources are retrieved on existing installs, so test after enabling. The Transcripts sources panel labels how each match was found while this is on.', 'mxchat'); ?></p>
1467 1608 </div>
1468 1609 </div>
1469 1610 </div>
1470 1611
@@ -1523,22 +1664,22 @@
1523 1664 /**
1524 1665 * Render Role Restrictions Section
1525 1666 */
1526 1667 function mxchat_render_role_restrictions_section($knowledge_manager) {
1527 - $role_options = array(
1528 - 'public' => __('Public (Everyone)', 'mxchat'),
1529 - 'logged_in' => __('Logged In Users', 'mxchat'),
1530 - 'subscriber' => __('Subscribers & Above', 'mxchat'),
1531 - 'contributor' => __('Contributors & Above', 'mxchat'),
1532 - 'author' => __('Authors & Above', 'mxchat'),
1533 - 'editor' => __('Editors & Above', 'mxchat'),
1534 - 'administrator' => __('Administrators Only', 'mxchat')
1535 - );
1668 + // Same source as the per-entry dropdown, so the two selectors cannot drift
1669 + // and both offer the site's custom roles (plan 6ab002). This screen used to
1670 + // hold its own hardcoded copy of the five built-ins.
1671 + $role_options = (is_object($knowledge_manager) && method_exists($knowledge_manager, 'mxchat_get_role_options'))
1672 + ? $knowledge_manager->mxchat_get_role_options()
1673 + : array(
1674 + 'public' => __('Public (Everyone)', 'mxchat'),
1675 + 'logged_in' => __('Logged In Users', 'mxchat'),
1676 + );
1536 1677 ?>
1537 1678 <div id="role-restrictions" class="mxch-section">
1538 1679 <div class="mxch-content-header">
1539 1680 <h1 class="mxch-content-title"><?php esc_html_e('Role-Based Content Restrictions', 'mxchat'); ?></h1>
1540 - <p class="mxch-content-subtitle"><?php esc_html_e('Automatically restrict content access based on WordPress tags.', 'mxchat'); ?></p>
1681 + <p class="mxch-content-subtitle"><?php esc_html_e('Automatically restrict tagged posts by role. Pages and untagged content are restricted per entry in the Knowledge list.', 'mxchat'); ?></p>
1541 1682 </div>
1542 1683
1543 1684 <div class="mxch-card">
1544 1685 <div class="mxch-card-body">
@@ -1543,9 +1684,9 @@
1543 1684 <div class="mxch-card">
1544 1685 <div class="mxch-card-body">
1545 1686 <div class="mxch-notice mxch-notice-info" style="margin-bottom: 20px;">
1546 1687 <svg class="mxch-notice-icon" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>
1547 - <span><strong><?php esc_html_e('How it works:', 'mxchat'); ?></strong> <?php esc_html_e('Add a tag below and select which role should have access. Content with that tag will be restricted to that role level.', 'mxchat'); ?></span>
1688 + <span><strong><?php esc_html_e('How it works:', 'mxchat'); ?></strong> <?php esc_html_e('Add a tag below and select which role should have access. Content with that tag will be restricted to that role level. Tags apply to posts — pages and other content have no tags, so restrict those from the role dropdown on the entry itself in the Knowledge list. Any role on this site can be chosen, including custom ones.', 'mxchat'); ?></span>
1548 1689 </div>
1549 1690
1550 1691 <h4 style="margin: 0 0 16px 0;"><?php esc_html_e('Add Tag-Role Mapping', 'mxchat'); ?></h4>
1551 1692 <div style="display: flex; gap: 15px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 24px;">
@@ -1837,8 +1978,59 @@
1837 1978 <a href="https://app.pinecone.io/" target="_blank"><?php esc_html_e('Open Pinecone Dashboard', 'mxchat'); ?></a>
1838 1979 </p>
1839 1980 </div>
1840 1981
1982 + <?php
1983 + // Index type (plan 362c31): the classic vector index (default) or a
1984 + // document index with full-text search. Same key, host and namespace.
1985 + $pc_index_type = (($pinecone_options['mxchat_pinecone_index_type'] ?? 'vector') === 'document') ? 'document' : 'vector';
1986 + $pc_docs_cloud = $pinecone_options['mxchat_pinecone_docs_cloud'] ?? 'aws';
1987 + $pc_docs_region = $pinecone_options['mxchat_pinecone_docs_region'] ?? 'us-east-1';
1988 + $pc_docs_lang = $pinecone_options['mxchat_pinecone_docs_language'] ?? 'en';
1989 + $pc_verified = $pinecone_options['mxchat_pinecone_docs_verified_host'] ?? '';
1990 + $pc_vector_host = $pinecone_options['mxchat_pinecone_vector_host'] ?? '';
1991 + $pc_current_host = $pinecone_options['mxchat_pinecone_host'] ?? '';
1992 + $pc_docs_class = class_exists('MxChat_Pinecone_Documents');
1993 + $pc_expected_dim = $pc_docs_class ? MxChat_Pinecone_Documents::expected_dimension() : 1536;
1994 + $pc_migration = $pc_docs_class ? MxChat_Pinecone_Documents::migration_get() : array();
1995 + $pc_host_verified = ($pc_current_host !== '' && strtolower(trim($pc_current_host, '/')) === strtolower($pc_verified));
1996 + $pc_clouds = $pc_docs_class ? MxChat_Pinecone_Documents::clouds() : array('aws' => 'AWS');
1997 + $pc_languages = $pc_docs_class ? MxChat_Pinecone_Documents::languages() : array('en' => 'English');
1998 + ?>
1999 + <div class="mxch-field" id="mxchat-pinecone-index-type-field">
2000 + <span class="mxch-field-label"><?php esc_html_e('Index type', 'mxchat'); ?></span>
2001 + <div style="display: flex; flex-direction: column; gap: 6px; margin-top: 8px;">
2002 + <label style="display: flex; align-items: baseline; gap: 8px; cursor: pointer;">
2003 + <input type="radio" name="mxchat_pinecone_addon_options[mxchat_pinecone_index_type]" class="mxchat-pinecone-index-type" value="vector" <?php checked($pc_index_type, 'vector'); ?>>
2004 + <span>
2005 + <strong><?php esc_html_e('Vector index (current)', 'mxchat'); ?></strong>
2006 + <span class="mxch-field-description" style="display: block; margin: 2px 0 0;"><?php esc_html_e('The classic Pinecone index. Nothing changes for existing setups.', 'mxchat'); ?></span>
2007 + </span>
2008 + </label>
2009 + <label style="display: flex; align-items: baseline; gap: 8px; cursor: pointer;">
2010 + <input type="radio" name="mxchat_pinecone_addon_options[mxchat_pinecone_index_type]" class="mxchat-pinecone-index-type" value="document" <?php checked($pc_index_type, 'document'); ?>>
2011 + <span>
2012 + <strong><?php esc_html_e('Document index with full-text search (new)', 'mxchat'); ?></strong>
2013 + <span class="mxch-field-description" style="display: block; margin: 2px 0 0;"><?php esc_html_e('A Pinecone document index keeps a keyword index of your content next to the vectors, so questions with part numbers, SKUs and codes find the exact record. It is a new index: create one below and copy your existing index into it, no re-embedding needed. Turn on the Hybrid keyword boost under Retrieval to use it.', 'mxchat'); ?></span>
2014 + </span>
2015 + </label>
2016 + </div>
2017 + </div>
2018 + <script type="application/json" id="mxchat-pinecone-docs-state"><?php echo wp_json_encode(array(
2019 + 'verified_host' => $pc_verified,
2020 + 'expected_dimension' => (int) $pc_expected_dim,
2021 + // 47c61f: the status notice's two texts, so the page can
2022 + // keep it in step with the host typed in the field.
2023 + 'status_checked' => __('Document index checked: %1$s (%2$d dimensions).', 'mxchat'),
2024 + 'status_unchecked' => __('Not checked yet. Create a document index below, or enter its host above and click Check index. The index type only saves once the host has been checked.', 'mxchat'),
2025 + 'migration' => $pc_migration,
2026 + // 3e83e4: what the LIVE chatbot is on right now, so the
2027 + // page can tell a copy-in-progress from a switch.
2028 + 'index_type' => $pc_index_type,
2029 + 'stored_host' => strtolower(trim((string) $pc_current_host, '/')),
2030 + 'stored_index' => (string) ($pinecone_options['mxchat_pinecone_index'] ?? ''),
2031 + )); ?></script>
2032 +
1841 2033 <div class="mxch-field">
1842 2034 <label class="mxch-field-label" for="mxchat_pinecone_environment"><?php esc_html_e('Region', 'mxchat'); ?></label>
1843 2035 <input type="text" id="mxchat_pinecone_environment" name="mxchat_pinecone_addon_options[mxchat_pinecone_environment]" value="<?php echo esc_attr($pinecone_options['mxchat_pinecone_environment'] ?? ''); ?>" class="mxch-input" placeholder="e.g., gcp-starter">
1844 2036 <p class="mxch-field-description"><?php esc_html_e('Your Pinecone environment/region (e.g., gcp-starter, us-west1-gcp)', 'mxchat'); ?></p>
@@ -1859,8 +2051,82 @@
1859 2051 <input type="text" id="mxchat_pinecone_host" name="mxchat_pinecone_addon_options[mxchat_pinecone_host]" value="<?php echo esc_attr($pinecone_options['mxchat_pinecone_host'] ?? ''); ?>" class="mxch-input" placeholder="e.g., my-index-xyz123.svc.pinecone.io">
1860 2052 <p class="mxch-field-description"><?php esc_html_e('The hostname from your Pinecone index URL (exclude https://). Found in index details.', 'mxchat'); ?></p>
1861 2053 </div>
1862 2054
2055 + <div class="mxchat-pinecone-docs-settings" <?php echo $pc_index_type === 'document' ? '' : 'style="display: none;"'; ?>>
2056 + <div class="mxch-notice <?php echo $pc_host_verified ? 'mxch-notice-success' : 'mxch-notice-warning'; ?>" id="mxchat-pinecone-docs-status" style="margin-bottom: 20px;">
2057 + <svg class="mxch-notice-icon" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>
2058 + <span id="mxchat-pinecone-docs-status-text"><?php
2059 + if ($pc_host_verified) {
2060 + printf(esc_html__('Document index checked: %1$s (%2$d dimensions).', 'mxchat'), esc_html($pc_verified), (int) $pc_expected_dim);
2061 + } else {
2062 + esc_html_e('Not checked yet. Create a document index below, or enter its host above and click Check index. The index type only saves once the host has been checked.', 'mxchat');
2063 + }
2064 + ?></span>
2065 + </div>
2066 +
2067 + <div class="mxch-field">
2068 + <label class="mxch-field-label" for="mxchat_pinecone_docs_cloud"><?php esc_html_e('Cloud and region for a new index', 'mxchat'); ?></label>
2069 + <div style="display: flex; gap: 8px; flex-wrap: wrap;">
2070 + <select id="mxchat_pinecone_docs_cloud" name="mxchat_pinecone_addon_options[mxchat_pinecone_docs_cloud]" class="mxch-select" style="max-width: 160px;">
2071 + <?php foreach ($pc_clouds as $pc_cloud_key => $pc_cloud_label) : ?>
2072 + <option value="<?php echo esc_attr($pc_cloud_key); ?>" <?php selected($pc_docs_cloud, $pc_cloud_key); ?>><?php echo esc_html($pc_cloud_label); ?></option>
2073 + <?php endforeach; ?>
2074 + </select>
2075 + <input type="text" id="mxchat_pinecone_docs_region" name="mxchat_pinecone_addon_options[mxchat_pinecone_docs_region]" value="<?php echo esc_attr($pc_docs_region); ?>" class="mxch-input" style="max-width: 220px;" placeholder="us-east-1">
2076 + <select id="mxchat_pinecone_docs_language" name="mxchat_pinecone_addon_options[mxchat_pinecone_docs_language]" class="mxch-select" style="max-width: 200px;">
2077 + <?php foreach ($pc_languages as $pc_lang_key => $pc_lang_label) : ?>
2078 + <option value="<?php echo esc_attr($pc_lang_key); ?>" <?php selected($pc_docs_lang, $pc_lang_key); ?>><?php echo esc_html($pc_lang_label); ?></option>
2079 + <?php endforeach; ?>
2080 + </select>
2081 + </div>
2082 + <p class="mxch-field-description"><?php printf(esc_html__('Create index for me makes a new document index named after the Index Name field (a free name ending in -docs is suggested when you switch to this type), sized for your embedding model (%d dimensions, cosine), with full-text search on the content in the chosen language, then fills in the host. Check index confirms the host above points at a document index MxChat can use. Neither moves your chatbot — that happens when you save.', 'mxchat'), (int) $pc_expected_dim); ?></p>
2083 + </div>
2084 +
2085 + <div class="mxch-field" style="display: flex; gap: 8px; flex-wrap: wrap;">
2086 + <button type="button" class="mxch-btn mxch-btn-secondary" id="mxchat-pinecone-docs-create"><?php esc_html_e('Create index for me', 'mxchat'); ?></button>
2087 + <button type="button" class="mxch-btn mxch-btn-secondary" id="mxchat-pinecone-docs-check"><?php esc_html_e('Check index', 'mxchat'); ?></button>
2088 + </div>
2089 + <div id="mxchat-pinecone-docs-result" style="display: none;"></div>
2090 + <p class="mxch-field-hint" id="mxchat-pinecone-docs-gate" style="display: none;"><?php esc_html_e('Check the document index host before saving.', 'mxchat'); ?></p>
2091 + <div class="mxch-field" id="mxchat-pinecone-docs-switch-gate" style="display: none;">
2092 + <p class="mxch-field-hint" id="mxchat-pinecone-docs-switch-gate-text"></p>
2093 + <label class="mxch-field-hint" style="display: flex; align-items: center; gap: 8px; cursor: pointer;">
2094 + <input type="checkbox" id="mxchat_pinecone_docs_switch_anyway" name="mxchat_pinecone_addon_options[mxchat_pinecone_docs_switch_anyway]" value="1">
2095 + <span><?php esc_html_e('Switch anyway — point the chatbot at the document index now and copy the rest afterwards', 'mxchat'); ?></span>
2096 + </label>
2097 + </div>
2098 +
2099 + <div class="mxch-field" style="margin-top: 20px;">
2100 + <label class="mxch-field-label" for="mxchat_pinecone_vector_host"><?php esc_html_e('Copy from vector index host', 'mxchat'); ?></label>
2101 + <input type="text" id="mxchat_pinecone_vector_host" name="mxchat_pinecone_addon_options[mxchat_pinecone_vector_host]" value="<?php echo esc_attr($pc_vector_host); ?>" class="mxch-input" placeholder="my-index-xyz123.svc.pinecone.io">
2102 + <p class="mxch-field-description"><?php esc_html_e('Migrate copies every record of that index into the document index above — text, vector and metadata, same ids — with no embedding calls. It runs while your chatbot keeps answering from the vector index; save the Pinecone settings afterwards to switch. Safe to run again: records already copied are simply replaced, and an interrupted copy continues where it stopped. Both indexes must use the same embedding dimension.', 'mxchat'); ?></p>
2103 + </div>
2104 + <div class="mxch-field" style="display: flex; gap: 12px; align-items: center; flex-wrap: wrap;">
2105 + <button type="button" class="mxch-btn mxch-btn-secondary" id="mxchat-pinecone-docs-migrate"><?php esc_html_e('Migrate', 'mxchat'); ?></button>
2106 + <?php /* e50d2e: offered only when the source index holds records in more than one namespace (the JS shows it from the start response). No name attribute — it is not a saved setting. */ ?>
2107 + <label class="mxch-toggle" id="mxchat-pinecone-docs-all-namespaces" style="display: none;" title="<?php esc_attr_e('Copy the records of every namespace of the vector index, each into the same-named namespace of the document index, in one run.', 'mxchat'); ?>">
2108 + <input type="checkbox" class="mxch-toggle-input" id="mxchat_pinecone_docs_all_namespaces" value="1">
2109 + <span class="mxch-toggle-switch"></span>
2110 + <span class="mxch-toggle-label"><?php esc_html_e('Copy every namespace', 'mxchat'); ?></span>
2111 + </label>
2112 + <span id="mxchat-pinecone-docs-migrate-counts" class="mxch-field-description"></span>
2113 + </div>
2114 + <div id="mxchat-pinecone-docs-migrate-progress" style="display: none; margin-bottom: 16px;">
2115 + <div class="mxch-progress-bar"><div class="mxch-progress-bar-fill" style="width: 0%;"></div></div>
2116 + <div class="mxch-progress-label"></div>
2117 + </div>
2118 +
2119 + <div class="mxch-field" id="mxchat-pinecone-docs-delete-old" style="display: none;">
2120 + <label class="mxch-field-label" for="mxchat_pinecone_docs_delete_confirm"><?php esc_html_e('Delete old index', 'mxchat'); ?></label>
2121 + <p class="mxch-field-description"><?php esc_html_e('Available once the copy count matches. Type the old index name to confirm. This deletes the whole vector index at Pinecone and cannot be undone.', 'mxchat'); ?></p>
2122 + <div style="display: flex; gap: 8px; flex-wrap: wrap;">
2123 + <input type="text" id="mxchat_pinecone_docs_delete_confirm" class="mxch-input" style="max-width: 320px;" placeholder="<?php esc_attr_e('old index name', 'mxchat'); ?>" autocomplete="off">
2124 + <button type="button" class="mxch-btn mxch-btn-danger" id="mxchat-pinecone-docs-delete-old-btn"><?php esc_html_e('Delete old index', 'mxchat'); ?></button>
2125 + </div>
2126 + </div>
2127 + </div>
2128 +
1863 2129 <div class="mxch-field">
1864 2130 <label class="mxch-field-label" for="mxchat_pinecone_top_k">
1865 2131 <?php esc_html_e('Results Per Query (topK)', 'mxchat'); ?>
1866 2132 </label>
@@ -2143,8 +2409,20 @@
2143 2409 <option value="processed"><?php esc_html_e('In Knowledge Base', 'mxchat'); ?></option>
2144 2410 <option value="unprocessed"><?php esc_html_e('Not In Knowledge Base', 'mxchat'); ?></option>
2145 2411 </select>
2146 2412 </div>
2413 + </div>
2414 + <?php
2415 + // Shown only while Media is the selected type (plan 01010a). Media lists
2416 + // just the files whose text MxChat can read; saying so here is clearer
2417 + // than listing images and audio as rows that cannot be selected.
2418 + ?>
2419 + <div class="mxchat-kb-filter-note" id="mxchat-kb-media-note" hidden>
2420 + <svg class="mxchat-kb-filter-note-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
2421 + <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
2422 + <path d="M14 2v6h6"></path>
2423 + </svg>
2424 + <span><?php esc_html_e('Media lists PDF, Word, text and Markdown files — the types MxChat can read text from. Images, audio and video are not shown.', 'mxchat'); ?></span>
2147 2425 </div>
2148 2426 <div class="mxchat-kb-content-selection">
2149 2427 <div class="mxchat-kb-selection-header">
2150 2428 <label>