| @@ -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); ?> |
| @@ -556,8 +602,19 @@ | ||
| 556 | 602 | <p><?php esc_html_e('Upload a PDF file from your computer.', 'mxchat'); ?></p> |
| 557 | 603 | </div> |
| 558 | 604 | </button> |
| 559 | 605 | |
| 606 | + <!-- Document File Upload Option (plan 0485e5) --> | |
| 607 | + <button type="button" class="mxchat-import-box" data-option="document-upload" data-type="document-upload"> | |
| 608 | + <div class="mxchat-import-icon"> | |
| 609 | + <span class="dashicons dashicons-media-text"></span> | |
| 610 | + </div> | |
| 611 | + <div class="mxchat-import-content"> | |
| 612 | + <h4><?php esc_html_e('Document Upload', 'mxchat'); ?></h4> | |
| 613 | + <p><?php esc_html_e('Upload a Word document, text, or Markdown file (.docx, .txt, .md).', 'mxchat'); ?></p> | |
| 614 | + </div> | |
| 615 | + </button> | |
| 616 | + | |
| 560 | 617 | <!-- YouTube Video Import Option --> |
| 561 | 618 | <button type="button" class="mxchat-import-box" data-option="youtube" data-type="youtube"> |
| 562 | 619 | <div class="mxchat-import-icon"> |
| 563 | 620 | <span class="dashicons dashicons-youtube"></span> |
| @@ -664,8 +721,14 @@ | ||
| 664 | 721 | </div> |
| 665 | 722 | <p class="mxch-field-description"> |
| 666 | 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'); ?> |
| 667 | 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> | |
| 668 | 731 | <button type="submit" name="submit_pdf_file" class="mxch-btn mxch-btn-primary"> |
| 669 | 732 | <?php esc_html_e('Import PDF', 'mxchat'); ?> |
| 670 | 733 | </button> |
| 671 | 734 | </form> |
| @@ -670,8 +733,32 @@ | ||
| 670 | 733 | </button> |
| 671 | 734 | </form> |
| 672 | 735 | </div> |
| 673 | 736 | |
| 737 | + <div class="mxchat-import-input-area" id="mxchat-document-upload-area" style="display: none; margin-top: 20px;"> | |
| 738 | + <form id="mxchat-document-upload-form" method="post" action="<?php echo esc_url(admin_url('admin-post.php?action=mxchat_submit_document_file')); ?>" enctype="multipart/form-data"> | |
| 739 | + <?php wp_nonce_field('mxchat_submit_document_file_action', 'mxchat_submit_document_file_nonce'); ?> | |
| 740 | + <?php if ($multibot_active && $current_bot_id !== 'default') : ?> | |
| 741 | + <input type="hidden" name="bot_id" value="<?php echo esc_attr($current_bot_id); ?>"> | |
| 742 | + <?php endif; ?> | |
| 743 | + <div class="mxch-field"> | |
| 744 | + <input type="file" name="document_file" id="mxchat-document-file-input" accept=".docx,.txt,.md" required> | |
| 745 | + </div> | |
| 746 | + <p class="mxch-field-description"> | |
| 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'); ?> | |
| 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> | |
| 755 | + <button type="submit" name="submit_document_file" class="mxch-btn mxch-btn-primary"> | |
| 756 | + <?php esc_html_e('Import Document', 'mxchat'); ?> | |
| 757 | + </button> | |
| 758 | + </form> | |
| 759 | + </div> | |
| 760 | + | |
| 674 | 761 | <?php |
| 675 | 762 | // Prefill state: set when an auto-import found no transcript — the |
| 676 | 763 | // handler bounced back here so the admin can augment the entry with |
| 677 | 764 | // a manual description (re-importing the same URL updates the row). |
| @@ -867,9 +954,10 @@ | ||
| 867 | 954 | <div class="mxch-card"> |
| 868 | 955 | <div class="mxch-card-header"> |
| 869 | 956 | <h3 class="mxch-card-title"> |
| 870 | 957 | <?php esc_html_e('Knowledge Entries', 'mxchat'); ?> |
| 871 | - <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> | |
| 872 | 960 | <?php if (!empty($use_vectorstore)) : ?> |
| 873 | 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;"> |
| 874 | 962 | <span class="dashicons dashicons-database" style="font-size: 14px;"></span> |
| 875 | 963 | <?php esc_html_e('Not in use', 'mxchat'); ?> |
| @@ -1059,9 +1147,8 @@ | ||
| 1059 | 1147 | data-nonce="<?php echo wp_create_nonce('mxchat_inspect_entry_nonce'); ?>" |
| 1060 | 1148 | title="<?php esc_attr_e('View indexed content', 'mxchat'); ?>"> |
| 1061 | 1149 | <span class="dashicons dashicons-visibility" style="font-size: 14px;"></span> |
| 1062 | 1150 | </button> |
| 1063 | - <?php if ($data_source !== 'pinecone') : ?> | |
| 1064 | 1151 | <button type="button" |
| 1065 | 1152 | class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-edit-entry-btn" |
| 1066 | 1153 | data-source-url="<?php echo esc_attr($source_url); ?>" |
| 1067 | 1154 | data-entry-id="<?php echo esc_attr($first_prompt->id); ?>" |
| @@ -1070,9 +1157,8 @@ | ||
| 1070 | 1157 | data-nonce="<?php echo wp_create_nonce('mxchat_edit_entry_nonce'); ?>" |
| 1071 | 1158 | title="<?php esc_attr_e('Edit content', 'mxchat'); ?>"> |
| 1072 | 1159 | <span class="dashicons dashicons-edit" style="font-size: 14px;"></span> |
| 1073 | 1160 | </button> |
| 1074 | - <?php endif; ?> | |
| 1075 | 1161 | <button type="button" |
| 1076 | 1162 | class="mxch-btn mxch-btn-ghost mxch-btn-sm delete-button-group" |
| 1077 | 1163 | data-source-url="<?php echo esc_attr($source_url); ?>" |
| 1078 | 1164 | data-chunk-count="<?php echo esc_attr($chunk_count); ?>" |
| @@ -1219,9 +1305,8 @@ | ||
| 1219 | 1305 | data-nonce="<?php echo wp_create_nonce('mxchat_inspect_entry_nonce'); ?>" |
| 1220 | 1306 | title="<?php esc_attr_e('View indexed content', 'mxchat'); ?>"> |
| 1221 | 1307 | <span class="dashicons dashicons-visibility" style="font-size: 14px;"></span> |
| 1222 | 1308 | </button> |
| 1223 | - <?php if ($data_source !== 'pinecone') : ?> | |
| 1224 | 1309 | <button type="button" |
| 1225 | 1310 | class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-edit-entry-btn" |
| 1226 | 1311 | data-source-url="<?php echo esc_attr($prompt->source_url ?? ''); ?>" |
| 1227 | 1312 | data-entry-id="<?php echo esc_attr($prompt->id); ?>" |
| @@ -1230,9 +1315,8 @@ | ||
| 1230 | 1315 | data-nonce="<?php echo wp_create_nonce('mxchat_edit_entry_nonce'); ?>" |
| 1231 | 1316 | title="<?php esc_attr_e('Edit content', 'mxchat'); ?>"> |
| 1232 | 1317 | <span class="dashicons dashicons-edit" style="font-size: 14px;"></span> |
| 1233 | 1318 | </button> |
| 1234 | - <?php endif; ?> | |
| 1235 | 1319 | <?php if ($data_source === 'pinecone') : ?> |
| 1236 | 1320 | <button type="button" class="mxch-btn mxch-btn-ghost mxch-btn-sm delete-button-ajax" data-vector-id="<?php echo esc_attr($prompt->id); ?>" data-bot-id="<?php echo esc_attr($current_bot_id); ?>" data-nonce="<?php echo wp_create_nonce('mxchat_delete_pinecone_prompt_nonce'); ?>" style="color: var(--mxch-error);"> |
| 1237 | 1321 | <span class="dashicons dashicons-trash" style="font-size: 14px;"></span> |
| 1238 | 1322 | </button> |
| @@ -1250,10 +1334,21 @@ | ||
| 1250 | 1334 | </table> |
| 1251 | 1335 | </div> |
| 1252 | 1336 | |
| 1253 | 1337 | <!-- Pagination wrapper - always present so JS can populate it after processing --> |
| 1254 | - <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); ?>"> | |
| 1255 | - <?php if ($total_pages > 1) : ?> | |
| 1338 | + <?php | |
| 1339 | + // Plan dd6e10: Pinecone's list endpoint is a cursor — there is no | |
| 1340 | + // random access to page N, so over 500 vectors the screen offers | |
| 1341 | + // Previous / Next only. The same markup is built for AJAX page | |
| 1342 | + // loads by MxChat_Knowledge_Manager::mxchat_cursor_pagination_html(). | |
| 1343 | + $cursor_pagination = !empty($cursor_pagination); | |
| 1344 | + $has_next = !empty($has_next); | |
| 1345 | + $show_pagination = $cursor_pagination ? ($current_page > 1 || $has_next) : ($total_pages > 1); | |
| 1346 | + ?> | |
| 1347 | + <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); ?>"> | |
| 1348 | + <?php if ($cursor_pagination) : ?> | |
| 1349 | + <?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 ?> | |
| 1350 | + <?php elseif ($total_pages > 1) : ?> | |
| 1256 | 1351 | <div class="mxchat-ajax-pagination" data-current-page="<?php echo esc_attr($current_page); ?>" data-total-pages="<?php echo esc_attr($total_pages); ?>"> |
| 1257 | 1352 | <?php if ($current_page > 1) : ?> |
| 1258 | 1353 | <a href="#" class="mxchat-page-link" data-page="<?php echo ($current_page - 1); ?>"><?php esc_html_e('« Previous', 'mxchat'); ?></a> |
| 1259 | 1354 | <?php endif; ?> |
| @@ -1292,13 +1387,85 @@ | ||
| 1292 | 1387 | <?php endif; ?> |
| 1293 | 1388 | </div> |
| 1294 | 1389 | </div> |
| 1295 | 1390 | </div> |
| 1391 | + | |
| 1392 | + <?php mxchat_render_kb_reimport_card(!empty($current_bot_id) ? $current_bot_id : 'default'); ?> | |
| 1296 | 1393 | </div> |
| 1297 | 1394 | <?php |
| 1298 | 1395 | } |
| 1299 | 1396 | |
| 1300 | 1397 | /** |
| 1398 | + * "Re-import affected entries" card (plan 89739b). | |
| 1399 | + * | |
| 1400 | + * The owner-facing side of wp mxchat kb-reimport: check first (no embedding | |
| 1401 | + * request, nothing written), read the list, then confirm. Both halves run in | |
| 1402 | + * resumable steps through the mxchat_kb_reimport AJAX action; the script is | |
| 1403 | + * js/knowledge-reimport.js. Everything dynamic is drawn there; this is the | |
| 1404 | + * resting markup. | |
| 1405 | + */ | |
| 1406 | +function mxchat_render_kb_reimport_card($current_bot_id = 'default') { | |
| 1407 | + if (!class_exists('MxChat_Knowledge_Manager')) { | |
| 1408 | + return; | |
| 1409 | + } | |
| 1410 | + ?> | |
| 1411 | + <div class="mxch-card mxch-kb-reimport" id="mxchat-kb-reimport" | |
| 1412 | + data-nonce="<?php echo esc_attr(wp_create_nonce('mxchat_kb_reimport')); ?>" | |
| 1413 | + data-bot="<?php echo esc_attr($current_bot_id); ?>"> | |
| 1414 | + <div class="mxch-card-header"> | |
| 1415 | + <h3 class="mxch-card-title"> | |
| 1416 | + <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> | |
| 1417 | + <?php esc_html_e('Re-import affected entries', 'mxchat'); ?> | |
| 1418 | + </h3> | |
| 1419 | + </div> | |
| 1420 | + <div class="mxch-card-body"> | |
| 1421 | + <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> | |
| 1422 | + | |
| 1423 | + <div class="mxch-kb-reimport-controls"> | |
| 1424 | + <div class="mxch-field"> | |
| 1425 | + <label class="mxch-field-label" for="mxchat-kb-reimport-before"><?php esc_html_e('Entries last written before', 'mxchat'); ?></label> | |
| 1426 | + <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)); ?>" /> | |
| 1427 | + </div> | |
| 1428 | + <button type="button" class="mxch-btn mxch-btn-secondary" id="mxchat-kb-reimport-check"><?php esc_html_e('Check knowledge base', 'mxchat'); ?></button> | |
| 1429 | + </div> | |
| 1430 | + <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> | |
| 1431 | + | |
| 1432 | + <div class="mxch-kb-reimport-progress" hidden> | |
| 1433 | + <div class="mxch-progress-bar" hidden><div class="mxch-progress-bar-fill"></div></div> | |
| 1434 | + <p class="mxch-progress-label" aria-live="polite"></p> | |
| 1435 | + </div> | |
| 1436 | + | |
| 1437 | + <div class="mxch-notice mxch-notice-error mxch-kb-reimport-error" role="alert" hidden> | |
| 1438 | + <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> | |
| 1439 | + <span></span> | |
| 1440 | + </div> | |
| 1441 | + | |
| 1442 | + <div class="mxch-kb-reimport-results" hidden> | |
| 1443 | + <div class="mxch-notice mxch-notice-success mxch-kb-reimport-done" hidden> | |
| 1444 | + <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> | |
| 1445 | + <span></span> | |
| 1446 | + </div> | |
| 1447 | + <div class="mxch-kb-reimport-counts"></div> | |
| 1448 | + <ul class="mxch-kb-reimport-list mxch-kb-reimport-entries" hidden></ul> | |
| 1449 | + <p class="mxch-field-hint mxch-kb-reimport-more" hidden></p> | |
| 1450 | + <details class="mxch-disclosure mxch-kb-reimport-others" hidden> | |
| 1451 | + <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> | |
| 1452 | + <div class="mxch-disclosure-body"> | |
| 1453 | + <ul class="mxch-kb-reimport-list mxch-kb-reimport-notes"></ul> | |
| 1454 | + </div> | |
| 1455 | + </details> | |
| 1456 | + </div> | |
| 1457 | + </div> | |
| 1458 | + <div class="mxch-card-footer mxch-kb-reimport-footer" hidden> | |
| 1459 | + <button type="button" class="mxch-btn mxch-btn-primary" id="mxchat-kb-reimport-apply"></button> | |
| 1460 | + <button type="button" class="mxch-btn mxch-btn-ghost" id="mxchat-kb-reimport-clear"><?php esc_html_e('Clear', 'mxchat'); ?></button> | |
| 1461 | + <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> | |
| 1462 | + </div> | |
| 1463 | + </div> | |
| 1464 | + <?php | |
| 1465 | +} | |
| 1466 | + | |
| 1467 | +/** | |
| 1301 | 1468 | * Render Auto-Sync Section |
| 1302 | 1469 | */ |
| 1303 | 1470 | function mxchat_render_auto_sync_section($knowledge_manager) { |
| 1304 | 1471 | ?> |
| @@ -1434,15 +1601,64 @@ | ||
| 1434 | 1601 | <label class="mxchat-toggle-switch"> |
| 1435 | 1602 | <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'); ?>> |
| 1436 | 1603 | <span class="mxchat-toggle-slider"></span> |
| 1437 | 1604 | </label> |
| 1438 | - <span style="font-weight: 500;"><?php esc_html_e('Hybrid keyword boost (WP-DB knowledge base)', 'mxchat'); ?></span> | |
| 1605 | + <span style="font-weight: 500;"><?php esc_html_e('Hybrid keyword boost (WordPress database and Pinecone document indexes)', 'mxchat'); ?></span> | |
| 1439 | 1606 | </div> |
| 1440 | - <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> | |
| 1441 | - <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> | |
| 1607 | + <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> | |
| 1608 | + <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> | |
| 1442 | 1609 | </div> |
| 1443 | 1610 | </div> |
| 1444 | 1611 | </div> |
| 1612 | + | |
| 1613 | + <?php | |
| 1614 | + // Video cards (plan f52492). Lives on the Knowledge screen because that | |
| 1615 | + // is where the owner imported the video in the first place, and beside | |
| 1616 | + // Retrieval because it is a retrieval-confidence question. Standalone | |
| 1617 | + // options — see the mxchat_video_embed_* cases in class-ajax-handler.php. | |
| 1618 | + $video_embed_enabled = MxChat_Utils::video_embed_enabled(); | |
| 1619 | + $video_embed_threshold = (int) round(MxChat_Utils::video_embed_threshold() * 100); | |
| 1620 | + $mxchat_core_options = get_option('mxchat_options', array()); | |
| 1621 | + $site_threshold = isset($mxchat_core_options['similarity_threshold']) | |
| 1622 | + ? (int) $mxchat_core_options['similarity_threshold'] | |
| 1623 | + : 35; | |
| 1624 | + ?> | |
| 1625 | + <div class="mxch-card"> | |
| 1626 | + <div class="mxch-card-header"> | |
| 1627 | + <h2 class="mxch-card-title"><?php esc_html_e('Video Cards', 'mxchat'); ?></h2> | |
| 1628 | + </div> | |
| 1629 | + <div class="mxch-card-body mxchat-autosave-section"> | |
| 1630 | + <div class="mxch-field" style="margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid var(--mxch-card-border);"> | |
| 1631 | + <div style="display: flex; align-items: center; gap: 12px;"> | |
| 1632 | + <label class="mxchat-toggle-switch"> | |
| 1633 | + <input type="checkbox" name="mxchat_video_embed_enabled" id="mxchat_video_embed_enabled" class="mxchat-autosave-field" value="on" <?php checked($video_embed_enabled, true); ?>> | |
| 1634 | + <span class="mxchat-toggle-slider"></span> | |
| 1635 | + </label> | |
| 1636 | + <span style="font-weight: 500;"><?php esc_html_e('Show a video card when a YouTube source answers the question', 'mxchat'); ?></span> | |
| 1637 | + </div> | |
| 1638 | + <p class="mxch-field-description" style="margin-top: 8px;"><?php esc_html_e('Adds a click-to-play card beneath the reply when the answer came from a YouTube video you imported. Turn this off to stop video cards entirely without removing the videos from your knowledge base.', 'mxchat'); ?></p> | |
| 1639 | + </div> | |
| 1640 | + | |
| 1641 | + <div class="mxch-field" id="mxchat-video-embed-threshold-field" style="<?php echo $video_embed_enabled ? '' : 'display: none;'; ?>"> | |
| 1642 | + <label class="mxch-field-label" for="mxchat_video_embed_threshold"><?php esc_html_e('Video Card Match Threshold (%)', 'mxchat'); ?></label> | |
| 1643 | + <?php // Slider matching the site-wide Similarity Threshold exactly | |
| 1644 | + // (plan 7afd54): same .slider-container / .range-slider / | |
| 1645 | + // .range-value markup; the shared admin JS live-updates the | |
| 1646 | + // <id>_value span on input and autosaves on change (once per | |
| 1647 | + // drag release, so no request storm). Range/default/clamp | |
| 1648 | + // unchanged — presentation only. ?> | |
| 1649 | + <div class="slider-container"> | |
| 1650 | + <input type="range" name="mxchat_video_embed_threshold" id="mxchat_video_embed_threshold" class="range-slider mxchat-autosave-field" value="<?php echo esc_attr($video_embed_threshold); ?>" min="20" max="95" step="1"> | |
| 1651 | + <span id="mxchat_video_embed_threshold_value" class="range-value"><?php echo esc_html((int) $video_embed_threshold); ?></span> | |
| 1652 | + </div> | |
| 1653 | + <p class="mxch-field-description"><?php | |
| 1654 | + /* translators: %d is the site-wide Similarity Threshold percentage. */ | |
| 1655 | + printf(esc_html__('How closely the video must match the question before its card is shown. Higher means fewer, more relevant cards. This is separate from the site-wide Similarity Threshold (currently %d%%), which decides what the AI reads — a video is worth reading from at a lower score than it is worth putting on screen.', 'mxchat'), (int) $site_threshold); | |
| 1656 | + ?></p> | |
| 1657 | + <p class="mxch-field-hint"><?php esc_html_e('Range 20-95. Raise this if visitors are shown videos unrelated to what they asked; lower it if a video that clearly answers the question is not appearing. The right number depends on your embedding model: older models such as text-embedding-ada-002 score even unrelated content around 70%, so those sites usually need 80 or higher before this has any effect. The Transcripts sources panel shows the match percentage of each source, which is the number to compare against.', 'mxchat'); ?></p> | |
| 1658 | + </div> | |
| 1659 | + </div> | |
| 1660 | + </div> | |
| 1445 | 1661 | </div> |
| 1446 | 1662 | <?php |
| 1447 | 1663 | } |
| 1448 | 1664 | |
| @@ -1449,22 +1665,22 @@ | ||
| 1449 | 1665 | /** |
| 1450 | 1666 | * Render Role Restrictions Section |
| 1451 | 1667 | */ |
| 1452 | 1668 | function mxchat_render_role_restrictions_section($knowledge_manager) { |
| 1453 | - $role_options = array( | |
| 1454 | - 'public' => __('Public (Everyone)', 'mxchat'), | |
| 1455 | - 'logged_in' => __('Logged In Users', 'mxchat'), | |
| 1456 | - 'subscriber' => __('Subscribers & Above', 'mxchat'), | |
| 1457 | - 'contributor' => __('Contributors & Above', 'mxchat'), | |
| 1458 | - 'author' => __('Authors & Above', 'mxchat'), | |
| 1459 | - 'editor' => __('Editors & Above', 'mxchat'), | |
| 1460 | - 'administrator' => __('Administrators Only', 'mxchat') | |
| 1461 | - ); | |
| 1669 | + // Same source as the per-entry dropdown, so the two selectors cannot drift | |
| 1670 | + // and both offer the site's custom roles (plan 6ab002). This screen used to | |
| 1671 | + // hold its own hardcoded copy of the five built-ins. | |
| 1672 | + $role_options = (is_object($knowledge_manager) && method_exists($knowledge_manager, 'mxchat_get_role_options')) | |
| 1673 | + ? $knowledge_manager->mxchat_get_role_options() | |
| 1674 | + : array( | |
| 1675 | + 'public' => __('Public (Everyone)', 'mxchat'), | |
| 1676 | + 'logged_in' => __('Logged In Users', 'mxchat'), | |
| 1677 | + ); | |
| 1462 | 1678 | ?> |
| 1463 | 1679 | <div id="role-restrictions" class="mxch-section"> |
| 1464 | 1680 | <div class="mxch-content-header"> |
| 1465 | 1681 | <h1 class="mxch-content-title"><?php esc_html_e('Role-Based Content Restrictions', 'mxchat'); ?></h1> |
| 1466 | - <p class="mxch-content-subtitle"><?php esc_html_e('Automatically restrict content access based on WordPress tags.', 'mxchat'); ?></p> | |
| 1682 | + <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> | |
| 1467 | 1683 | </div> |
| 1468 | 1684 | |
| 1469 | 1685 | <div class="mxch-card"> |
| 1470 | 1686 | <div class="mxch-card-body"> |
| @@ -1469,9 +1685,9 @@ | ||
| 1469 | 1685 | <div class="mxch-card"> |
| 1470 | 1686 | <div class="mxch-card-body"> |
| 1471 | 1687 | <div class="mxch-notice mxch-notice-info" style="margin-bottom: 20px;"> |
| 1472 | 1688 | <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> |
| 1473 | - <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> | |
| 1689 | + <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> | |
| 1474 | 1690 | </div> |
| 1475 | 1691 | |
| 1476 | 1692 | <h4 style="margin: 0 0 16px 0;"><?php esc_html_e('Add Tag-Role Mapping', 'mxchat'); ?></h4> |
| 1477 | 1693 | <div style="display: flex; gap: 15px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 24px;"> |
| @@ -1573,30 +1789,55 @@ | ||
| 1573 | 1789 | </div> |
| 1574 | 1790 | <?php else: ?> |
| 1575 | 1791 | <div class="mxch-notice mxch-notice-info" style="margin-bottom: 20px;"> |
| 1576 | 1792 | <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> |
| 1577 | - <span><?php esc_html_e('Toggle fields ON to include them in knowledge base embeddings. Toggle OFF to exclude sensitive or irrelevant fields.', 'mxchat'); ?></span> | |
| 1793 | + <span><?php esc_html_e('Toggle fields ON to include them in knowledge base embeddings. Toggle OFF to exclude sensitive or irrelevant fields. Exclusions apply everywhere a field appears — ACF location rules (post types, templates) do not scope this list.', 'mxchat'); ?></span> | |
| 1578 | 1794 | </div> |
| 1579 | 1795 | |
| 1580 | - <?php foreach ($all_acf_fields as $group_title => $fields): ?> | |
| 1581 | - <div class="mxchat-acf-field-group" style="margin-bottom: 24px;"> | |
| 1582 | - <h4 style="margin: 0 0 12px 0; color: var(--mxch-text-primary); font-weight: 600;"> | |
| 1583 | - <?php echo esc_html($group_title); ?> | |
| 1584 | - </h4> | |
| 1796 | + <?php foreach ($all_acf_fields as $group_key => $group): | |
| 1797 | + $fields = $group['fields']; | |
| 1798 | + // Group toggle state derives from the per-field state — | |
| 1799 | + // never stored on its own (plan bf57e0). | |
| 1800 | + $excluded_count = 0; | |
| 1801 | + foreach ($fields as $field) { | |
| 1802 | + if (in_array($field['key'], $excluded_fields, true) || in_array($field['name'], $excluded_fields, true)) { | |
| 1803 | + $excluded_count++; | |
| 1804 | + } | |
| 1805 | + } | |
| 1806 | + $group_all_included = ($excluded_count === 0); | |
| 1807 | + $group_partial = ($excluded_count > 0 && $excluded_count < count($fields)); | |
| 1808 | + ?> | |
| 1809 | + <div class="mxchat-acf-field-group" style="margin-bottom: 24px;" data-mxchat-acf-group="<?php echo esc_attr($group_key); ?>"> | |
| 1810 | + <div style="display: flex; align-items: center; justify-content: space-between; margin: 0 0 12px 0;"> | |
| 1811 | + <h4 style="margin: 0; color: var(--mxch-text-primary); font-weight: 600;"> | |
| 1812 | + <?php echo esc_html($group['title']); ?> | |
| 1813 | + </h4> | |
| 1814 | + <label class="mxchat-toggle-switch" title="<?php esc_attr_e('Include or exclude every field in this group', 'mxchat'); ?>"> | |
| 1815 | + <input type="checkbox" | |
| 1816 | + class="mxchat-acf-group-toggle" | |
| 1817 | + data-group-key="<?php echo esc_attr($group_key); ?>" | |
| 1818 | + data-nonce="<?php echo wp_create_nonce('mxchat_prompts_setting_nonce'); ?>" | |
| 1819 | + <?php if ($group_partial): ?>data-indeterminate="1"<?php endif; ?> | |
| 1820 | + <?php checked($group_all_included, true); ?>> | |
| 1821 | + <span class="mxchat-toggle-slider"></span> | |
| 1822 | + </label> | |
| 1823 | + </div> | |
| 1585 | 1824 | <div style="background: #f8fafc; border-radius: var(--mxch-radius-md); padding: 16px;"> |
| 1586 | 1825 | <?php foreach ($fields as $field): |
| 1587 | - $field_name = $field['name']; | |
| 1588 | - $is_enabled = !in_array($field_name, $excluded_fields); | |
| 1826 | + // Toggles identify fields by ACF field KEY — names are shared | |
| 1827 | + // across groups and collide (plan 30e81f). Legacy name entries | |
| 1828 | + // (group inactive at migration time) still count as excluded. | |
| 1829 | + $is_enabled = !in_array($field['key'], $excluded_fields, true) && !in_array($field['name'], $excluded_fields, true); | |
| 1589 | 1830 | ?> |
| 1590 | 1831 | <div style="display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #e2e8f0;"> |
| 1591 | 1832 | <div> |
| 1592 | 1833 | <span style="font-weight: 500;"><?php echo esc_html($field['label']); ?></span> |
| 1593 | - <span style="color: var(--mxch-text-muted); font-size: 12px; margin-left: 8px;">(<?php echo esc_html($field_name); ?>)</span> | |
| 1834 | + <span style="color: var(--mxch-text-muted); font-size: 12px; margin-left: 8px;">(<?php echo esc_html($field['name']); ?>)</span> | |
| 1594 | 1835 | <span style="color: var(--mxch-text-muted); font-size: 11px; margin-left: 8px; background: #e2e8f0; padding: 2px 6px; border-radius: 4px;"><?php echo esc_html($field['type']); ?></span> |
| 1595 | 1836 | </div> |
| 1596 | 1837 | <label class="mxchat-toggle-switch"> |
| 1597 | 1838 | <input type="checkbox" |
| 1598 | - name="mxchat_acf_field_<?php echo esc_attr($field_name); ?>" | |
| 1839 | + name="mxchat_acf_field_<?php echo esc_attr($field['key']); ?>" | |
| 1599 | 1840 | class="mxchat-autosave-field" |
| 1600 | 1841 | value="on" |
| 1601 | 1842 | data-nonce="<?php echo wp_create_nonce('mxchat_prompts_setting_nonce'); ?>" |
| 1602 | 1843 | <?php checked($is_enabled, true); ?>> |
| @@ -1738,8 +1979,59 @@ | ||
| 1738 | 1979 | <a href="https://app.pinecone.io/" target="_blank"><?php esc_html_e('Open Pinecone Dashboard', 'mxchat'); ?></a> |
| 1739 | 1980 | </p> |
| 1740 | 1981 | </div> |
| 1741 | 1982 | |
| 1983 | + <?php | |
| 1984 | + // Index type (plan 362c31): the classic vector index (default) or a | |
| 1985 | + // document index with full-text search. Same key, host and namespace. | |
| 1986 | + $pc_index_type = (($pinecone_options['mxchat_pinecone_index_type'] ?? 'vector') === 'document') ? 'document' : 'vector'; | |
| 1987 | + $pc_docs_cloud = $pinecone_options['mxchat_pinecone_docs_cloud'] ?? 'aws'; | |
| 1988 | + $pc_docs_region = $pinecone_options['mxchat_pinecone_docs_region'] ?? 'us-east-1'; | |
| 1989 | + $pc_docs_lang = $pinecone_options['mxchat_pinecone_docs_language'] ?? 'en'; | |
| 1990 | + $pc_verified = $pinecone_options['mxchat_pinecone_docs_verified_host'] ?? ''; | |
| 1991 | + $pc_vector_host = $pinecone_options['mxchat_pinecone_vector_host'] ?? ''; | |
| 1992 | + $pc_current_host = $pinecone_options['mxchat_pinecone_host'] ?? ''; | |
| 1993 | + $pc_docs_class = class_exists('MxChat_Pinecone_Documents'); | |
| 1994 | + $pc_expected_dim = $pc_docs_class ? MxChat_Pinecone_Documents::expected_dimension() : 1536; | |
| 1995 | + $pc_migration = $pc_docs_class ? MxChat_Pinecone_Documents::migration_get() : array(); | |
| 1996 | + $pc_host_verified = ($pc_current_host !== '' && strtolower(trim($pc_current_host, '/')) === strtolower($pc_verified)); | |
| 1997 | + $pc_clouds = $pc_docs_class ? MxChat_Pinecone_Documents::clouds() : array('aws' => 'AWS'); | |
| 1998 | + $pc_languages = $pc_docs_class ? MxChat_Pinecone_Documents::languages() : array('en' => 'English'); | |
| 1999 | + ?> | |
| 2000 | + <div class="mxch-field" id="mxchat-pinecone-index-type-field"> | |
| 2001 | + <span class="mxch-field-label"><?php esc_html_e('Index type', 'mxchat'); ?></span> | |
| 2002 | + <div style="display: flex; flex-direction: column; gap: 6px; margin-top: 8px;"> | |
| 2003 | + <label style="display: flex; align-items: baseline; gap: 8px; cursor: pointer;"> | |
| 2004 | + <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'); ?>> | |
| 2005 | + <span> | |
| 2006 | + <strong><?php esc_html_e('Vector index (current)', 'mxchat'); ?></strong> | |
| 2007 | + <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> | |
| 2008 | + </span> | |
| 2009 | + </label> | |
| 2010 | + <label style="display: flex; align-items: baseline; gap: 8px; cursor: pointer;"> | |
| 2011 | + <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'); ?>> | |
| 2012 | + <span> | |
| 2013 | + <strong><?php esc_html_e('Document index with full-text search (new)', 'mxchat'); ?></strong> | |
| 2014 | + <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> | |
| 2015 | + </span> | |
| 2016 | + </label> | |
| 2017 | + </div> | |
| 2018 | + </div> | |
| 2019 | + <script type="application/json" id="mxchat-pinecone-docs-state"><?php echo wp_json_encode(array( | |
| 2020 | + 'verified_host' => $pc_verified, | |
| 2021 | + 'expected_dimension' => (int) $pc_expected_dim, | |
| 2022 | + // 47c61f: the status notice's two texts, so the page can | |
| 2023 | + // keep it in step with the host typed in the field. | |
| 2024 | + 'status_checked' => __('Document index checked: %1$s (%2$d dimensions).', 'mxchat'), | |
| 2025 | + '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'), | |
| 2026 | + 'migration' => $pc_migration, | |
| 2027 | + // 3e83e4: what the LIVE chatbot is on right now, so the | |
| 2028 | + // page can tell a copy-in-progress from a switch. | |
| 2029 | + 'index_type' => $pc_index_type, | |
| 2030 | + 'stored_host' => strtolower(trim((string) $pc_current_host, '/')), | |
| 2031 | + 'stored_index' => (string) ($pinecone_options['mxchat_pinecone_index'] ?? ''), | |
| 2032 | + )); ?></script> | |
| 2033 | + | |
| 1742 | 2034 | <div class="mxch-field"> |
| 1743 | 2035 | <label class="mxch-field-label" for="mxchat_pinecone_environment"><?php esc_html_e('Region', 'mxchat'); ?></label> |
| 1744 | 2036 | <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"> |
| 1745 | 2037 | <p class="mxch-field-description"><?php esc_html_e('Your Pinecone environment/region (e.g., gcp-starter, us-west1-gcp)', 'mxchat'); ?></p> |
| @@ -1759,8 +2051,90 @@ | ||
| 1759 | 2051 | </label> |
| 1760 | 2052 | <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"> |
| 1761 | 2053 | <p class="mxch-field-description"><?php esc_html_e('The hostname from your Pinecone index URL (exclude https://). Found in index details.', 'mxchat'); ?></p> |
| 1762 | 2054 | </div> |
| 2055 | + | |
| 2056 | + <div class="mxchat-pinecone-docs-settings" <?php echo $pc_index_type === 'document' ? '' : 'style="display: none;"'; ?>> | |
| 2057 | + <div class="mxch-notice <?php echo $pc_host_verified ? 'mxch-notice-success' : 'mxch-notice-warning'; ?>" id="mxchat-pinecone-docs-status" style="margin-bottom: 20px;"> | |
| 2058 | + <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> | |
| 2059 | + <span id="mxchat-pinecone-docs-status-text"><?php | |
| 2060 | + if ($pc_host_verified) { | |
| 2061 | + printf(esc_html__('Document index checked: %1$s (%2$d dimensions).', 'mxchat'), esc_html($pc_verified), (int) $pc_expected_dim); | |
| 2062 | + } else { | |
| 2063 | + 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'); | |
| 2064 | + } | |
| 2065 | + ?></span> | |
| 2066 | + </div> | |
| 2067 | + | |
| 2068 | + <div class="mxch-field"> | |
| 2069 | + <label class="mxch-field-label" for="mxchat_pinecone_docs_cloud"><?php esc_html_e('Cloud and region for a new index', 'mxchat'); ?></label> | |
| 2070 | + <div style="display: flex; gap: 8px; flex-wrap: wrap;"> | |
| 2071 | + <select id="mxchat_pinecone_docs_cloud" name="mxchat_pinecone_addon_options[mxchat_pinecone_docs_cloud]" class="mxch-select" style="max-width: 160px;"> | |
| 2072 | + <?php foreach ($pc_clouds as $pc_cloud_key => $pc_cloud_label) : ?> | |
| 2073 | + <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> | |
| 2074 | + <?php endforeach; ?> | |
| 2075 | + </select> | |
| 2076 | + <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"> | |
| 2077 | + <select id="mxchat_pinecone_docs_language" name="mxchat_pinecone_addon_options[mxchat_pinecone_docs_language]" class="mxch-select" style="max-width: 200px;"> | |
| 2078 | + <?php foreach ($pc_languages as $pc_lang_key => $pc_lang_label) : ?> | |
| 2079 | + <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> | |
| 2080 | + <?php endforeach; ?> | |
| 2081 | + </select> | |
| 2082 | + </div> | |
| 2083 | + <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> | |
| 2084 | + </div> | |
| 2085 | + | |
| 2086 | + <div class="mxch-field" style="display: flex; gap: 8px; flex-wrap: wrap;"> | |
| 2087 | + <button type="button" class="mxch-btn mxch-btn-secondary" id="mxchat-pinecone-docs-create"><?php esc_html_e('Create index for me', 'mxchat'); ?></button> | |
| 2088 | + <button type="button" class="mxch-btn mxch-btn-secondary" id="mxchat-pinecone-docs-check"><?php esc_html_e('Check index', 'mxchat'); ?></button> | |
| 2089 | + </div> | |
| 2090 | + <div id="mxchat-pinecone-docs-result" style="display: none;"></div> | |
| 2091 | + <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> | |
| 2092 | + <div class="mxch-field" id="mxchat-pinecone-docs-switch-gate" style="display: none;"> | |
| 2093 | + <p class="mxch-field-hint" id="mxchat-pinecone-docs-switch-gate-text"></p> | |
| 2094 | + <label class="mxch-field-hint" style="display: flex; align-items: center; gap: 8px; cursor: pointer;"> | |
| 2095 | + <input type="checkbox" id="mxchat_pinecone_docs_switch_anyway" name="mxchat_pinecone_addon_options[mxchat_pinecone_docs_switch_anyway]" value="1"> | |
| 2096 | + <span><?php esc_html_e('Switch anyway — point the chatbot at the document index now and copy the rest afterwards', 'mxchat'); ?></span> | |
| 2097 | + </label> | |
| 2098 | + </div> | |
| 2099 | + | |
| 2100 | + <div class="mxch-field" style="margin-top: 20px;"> | |
| 2101 | + <label class="mxch-field-label" for="mxchat_pinecone_vector_host"><?php esc_html_e('Copy from vector index host', 'mxchat'); ?></label> | |
| 2102 | + <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"> | |
| 2103 | + <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> | |
| 2104 | + </div> | |
| 2105 | + <div class="mxch-field" style="display: flex; gap: 12px; align-items: center; flex-wrap: wrap;"> | |
| 2106 | + <button type="button" class="mxch-btn mxch-btn-secondary" id="mxchat-pinecone-docs-migrate"><?php esc_html_e('Migrate', 'mxchat'); ?></button> | |
| 2107 | + <?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. */ ?> | |
| 2108 | + <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'); ?>"> | |
| 2109 | + <input type="checkbox" class="mxch-toggle-input" id="mxchat_pinecone_docs_all_namespaces" value="1"> | |
| 2110 | + <span class="mxch-toggle-switch"></span> | |
| 2111 | + <span class="mxch-toggle-label"><?php esc_html_e('Copy every namespace', 'mxchat'); ?></span> | |
| 2112 | + </label> | |
| 2113 | + <span id="mxchat-pinecone-docs-migrate-counts" class="mxch-field-description"></span> | |
| 2114 | + </div> | |
| 2115 | + <div id="mxchat-pinecone-docs-migrate-progress" style="display: none; margin-bottom: 16px;"> | |
| 2116 | + <div class="mxch-progress-bar"><div class="mxch-progress-bar-fill" style="width: 0%;"></div></div> | |
| 2117 | + <div class="mxch-progress-label"></div> | |
| 2118 | + </div> | |
| 2119 | + | |
| 2120 | + <div class="mxch-field" id="mxchat-pinecone-docs-delete-old" style="display: none;"> | |
| 2121 | + <label class="mxch-field-label" for="mxchat_pinecone_docs_delete_confirm"><?php esc_html_e('Delete old index', 'mxchat'); ?></label> | |
| 2122 | + <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> | |
| 2123 | + <div style="display: flex; gap: 8px; flex-wrap: wrap;"> | |
| 2124 | + <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"> | |
| 2125 | + <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> | |
| 2126 | + </div> | |
| 2127 | + </div> | |
| 2128 | + </div> | |
| 2129 | + | |
| 2130 | + <div class="mxch-field"> | |
| 2131 | + <label class="mxch-field-label" for="mxchat_pinecone_top_k"> | |
| 2132 | + <?php esc_html_e('Results Per Query (topK)', 'mxchat'); ?> | |
| 2133 | + </label> | |
| 2134 | + <input type="number" id="mxchat_pinecone_top_k" name="mxchat_pinecone_addon_options[mxchat_pinecone_top_k]" value="<?php echo esc_attr($pinecone_options['mxchat_pinecone_top_k'] ?? '50'); ?>" class="mxch-input" min="1" max="1000" step="1" placeholder="50"> | |
| 2135 | + <p class="mxch-field-description"><?php esc_html_e('How many candidate matches each Pinecone query requests (1-1000, default 50). Higher values improve grouping of chunked content at the cost of slightly larger responses.', 'mxchat'); ?></p> | |
| 2136 | + </div> | |
| 1763 | 2137 | </div> |
| 1764 | 2138 | |
| 1765 | 2139 | <?php submit_button(__('Save Pinecone Settings', 'mxchat'), 'primary', 'submit', true, array('class' => 'mxch-btn mxch-btn-primary')); ?> |
| 1766 | 2140 | </form> |
| @@ -1777,8 +2151,12 @@ | ||
| 1777 | 2151 | $vectorstore_options = get_option('mxchat_openai_vectorstore_options', array()); |
| 1778 | 2152 | $use_vectorstore = $vectorstore_options['mxchat_use_openai_vectorstore'] ?? '0'; |
| 1779 | 2153 | $vectorstore_ids = $vectorstore_options['mxchat_vectorstore_ids'] ?? ''; |
| 1780 | 2154 | $max_results = $vectorstore_options['mxchat_vectorstore_max_results'] ?? 5; |
| 2155 | + $sync_enabled = $vectorstore_options['mxchat_vectorstore_sync_enabled'] ?? '0'; | |
| 2156 | + $sync_store_id = $vectorstore_options['mxchat_vectorstore_sync_store_id'] ?? ''; | |
| 2157 | + $sync_config = class_exists('MxChat_Vectorstore_Manager') ? MxChat_Vectorstore_Manager::get_sync_config('default') : array('enabled' => false, 'store_id' => ''); | |
| 2158 | + $mapped_count = class_exists('MxChat_Vectorstore_Manager') ? MxChat_Vectorstore_Manager::mapped_file_count() : 0; | |
| 1781 | 2159 | |
| 1782 | 2160 | // Get current chat model to check compatibility |
| 1783 | 2161 | $mxchat_options = get_option('mxchat_options', array()); |
| 1784 | 2162 | $current_model = $mxchat_options['model'] ?? 'gpt-5.6-sol'; |
| @@ -1848,10 +2226,143 @@ | ||
| 1848 | 2226 | <p class="mxch-field-description"><?php esc_html_e('Maximum number of content chunks to retrieve from the Vector Store.', 'mxchat'); ?></p> |
| 1849 | 2227 | </div> |
| 1850 | 2228 | </div> |
| 1851 | 2229 | |
| 2230 | + <div class="mxch-field" style="border-top: 1px solid var(--mxch-border, #e2e4e7); padding-top: 20px; margin-top: 4px;"> | |
| 2231 | + <div style="display: flex; align-items: center; gap: 12px; margin-bottom: 8px;"> | |
| 2232 | + <label class="mxchat-toggle-switch"> | |
| 2233 | + <input type="checkbox" name="mxchat_openai_vectorstore_options[mxchat_vectorstore_sync_enabled]" value="1" <?php checked($sync_enabled, '1'); ?> id="mxchat_vectorstore_sync_enabled"> | |
| 2234 | + <span class="mxchat-toggle-slider"></span> | |
| 2235 | + </label> | |
| 2236 | + <span style="font-weight: 500;"><?php esc_html_e('Sync Knowledge Base to Vector Store', 'mxchat'); ?></span> | |
| 2237 | + </div> | |
| 2238 | + <p class="mxch-field-description" style="margin-bottom: 16px;"> | |
| 2239 | + <?php esc_html_e('Keeps your Vector Store up to date automatically: knowledge base additions, edits, and deletions are mirrored to the store (one file per entry, replaced on change). Without this, the store is frozen at whatever you uploaded manually. Role-restricted entries are never uploaded — OpenAI file search cannot filter by user role.', 'mxchat'); ?> | |
| 2240 | + </p> | |
| 2241 | + | |
| 2242 | + <label class="mxch-field-label" for="mxchat_vectorstore_sync_store_id"> | |
| 2243 | + <?php esc_html_e('Sync Target Vector Store ID', 'mxchat'); ?> | |
| 2244 | + </label> | |
| 2245 | + <input type="text" id="mxchat_vectorstore_sync_store_id" name="mxchat_openai_vectorstore_options[mxchat_vectorstore_sync_store_id]" value="<?php echo esc_attr($sync_store_id); ?>" class="mxch-input" placeholder="<?php echo esc_attr($sync_config['store_id'] ?: 'vs_abc123xyz'); ?>"> | |
| 2246 | + <p class="mxch-field-description"> | |
| 2247 | + <?php esc_html_e('Leave blank to use the first Vector Store ID above. Syncing writes to exactly one store.', 'mxchat'); ?> | |
| 2248 | + </p> | |
| 2249 | + </div> | |
| 2250 | + | |
| 1852 | 2251 | <?php submit_button(__('Save Vector Store Settings', 'mxchat'), 'primary', 'submit', true, array('class' => 'mxch-btn mxch-btn-primary')); ?> |
| 1853 | 2252 | </form> |
| 2253 | + | |
| 2254 | + <?php if ($sync_config['enabled']): ?> | |
| 2255 | + <div class="mxch-field" id="mxchat-vs-import" style="border-top: 1px solid var(--mxch-border, #e2e4e7); padding-top: 20px;" | |
| 2256 | + data-nonce="<?php echo esc_attr(wp_create_nonce('mxchat_admin_nonce')); ?>"> | |
| 2257 | + <label class="mxch-field-label"><?php esc_html_e('Import Existing Knowledge Base', 'mxchat'); ?></label> | |
| 2258 | + <p class="mxch-field-description"> | |
| 2259 | + <?php printf(esc_html__('One-time (re-runnable) import of every knowledge base entry into the sync target store. Runs in the background via WP-Cron; safe to interrupt and resume — already-imported, unchanged entries are skipped. Currently mirrored: %s files.', 'mxchat'), '<strong id="mxchat-vs-mapped">' . esc_html(number_format_i18n($mapped_count)) . '</strong>'); ?> | |
| 2260 | + </p> | |
| 2261 | + <div style="display: flex; align-items: center; gap: 8px; margin: 10px 0;"> | |
| 2262 | + <button type="button" class="mxch-btn mxch-btn-secondary" id="mxchat-vs-import-start"><?php esc_html_e('Import Knowledge Base to Vector Store', 'mxchat'); ?></button> | |
| 2263 | + <button type="button" class="mxch-btn" id="mxchat-vs-import-resume" style="display:none;"><?php esc_html_e('Resume Import', 'mxchat'); ?></button> | |
| 2264 | + <button type="button" class="mxch-btn" id="mxchat-vs-import-cancel" style="display:none;"><?php esc_html_e('Cancel', 'mxchat'); ?></button> | |
| 2265 | + </div> | |
| 2266 | + <div id="mxchat-vs-import-bar" style="display:none; height: 8px; background: var(--mxch-border, #e2e4e7); border-radius: 4px; overflow: hidden; max-width: 420px;"> | |
| 2267 | + <div id="mxchat-vs-import-fill" style="height: 100%; width: 0%; background: #2271b1; transition: width .4s;"></div> | |
| 2268 | + </div> | |
| 2269 | + <p class="mxch-field-description" id="mxchat-vs-import-status" style="margin-top: 8px;"></p> | |
| 2270 | + </div> | |
| 2271 | + | |
| 2272 | + <script> | |
| 2273 | + (function() { | |
| 2274 | + var wrap = document.getElementById('mxchat-vs-import'); | |
| 2275 | + if (!wrap) { return; } | |
| 2276 | + var nonce = wrap.getAttribute('data-nonce'); | |
| 2277 | + var startBtn = document.getElementById('mxchat-vs-import-start'); | |
| 2278 | + var resumeBtn = document.getElementById('mxchat-vs-import-resume'); | |
| 2279 | + var cancelBtn = document.getElementById('mxchat-vs-import-cancel'); | |
| 2280 | + var bar = document.getElementById('mxchat-vs-import-bar'); | |
| 2281 | + var fill = document.getElementById('mxchat-vs-import-fill'); | |
| 2282 | + var statusEl = document.getElementById('mxchat-vs-import-status'); | |
| 2283 | + var mappedEl = document.getElementById('mxchat-vs-mapped'); | |
| 2284 | + var pollTimer = null; | |
| 2285 | + | |
| 2286 | + function post(action, done) { | |
| 2287 | + var body = 'action=' + encodeURIComponent(action) + '&nonce=' + encodeURIComponent(nonce); | |
| 2288 | + fetch(ajaxurl, { | |
| 2289 | + method: 'POST', | |
| 2290 | + credentials: 'same-origin', | |
| 2291 | + headers: {'Content-Type': 'application/x-www-form-urlencoded'}, | |
| 2292 | + body: body | |
| 2293 | + }).then(function(r) { return r.json(); }).then(done).catch(function() { | |
| 2294 | + statusEl.textContent = '<?php echo esc_js(__('Request failed — check the browser console.', 'mxchat')); ?>'; | |
| 2295 | + }); | |
| 2296 | + } | |
| 2297 | + | |
| 2298 | + function render(state, mapped) { | |
| 2299 | + if (typeof mapped === 'number' && mappedEl) { mappedEl.textContent = mapped.toLocaleString(); } | |
| 2300 | + var running = state.status === 'running'; | |
| 2301 | + startBtn.style.display = running ? 'none' : ''; | |
| 2302 | + cancelBtn.style.display = running ? '' : 'none'; | |
| 2303 | + resumeBtn.style.display = (running && state.stalled) ? '' : 'none'; | |
| 2304 | + bar.style.display = (running || state.status === 'done') ? '' : 'none'; | |
| 2305 | + var pct = state.total > 0 ? Math.min(100, Math.round(state.processed / state.total * 100)) : 0; | |
| 2306 | + if (state.status === 'done') { pct = 100; } | |
| 2307 | + fill.style.width = pct + '%'; | |
| 2308 | + | |
| 2309 | + var bits = []; | |
| 2310 | + if (state.status === 'running') { bits.push(state.stalled ? '<?php echo esc_js(__('Import stalled (cron missed) — click Resume.', 'mxchat')); ?>' : '<?php echo esc_js(__('Importing…', 'mxchat')); ?>'); } | |
| 2311 | + if (state.status === 'done') { bits.push('<?php echo esc_js(__('Import complete.', 'mxchat')); ?>'); } | |
| 2312 | + if (state.status === 'cancelled') { bits.push('<?php echo esc_js(__('Import cancelled.', 'mxchat')); ?>'); } | |
| 2313 | + if (state.status === 'error') { bits.push('<?php echo esc_js(__('Import error:', 'mxchat')); ?> ' + state.last_error); } | |
| 2314 | + if (state.status !== 'idle') { | |
| 2315 | + bits.push(state.processed + '/' + state.total | |
| 2316 | + + ' — ' + state.imported + ' <?php echo esc_js(__('uploaded', 'mxchat')); ?>' | |
| 2317 | + + ', ' + state.unchanged + ' <?php echo esc_js(__('unchanged', 'mxchat')); ?>' | |
| 2318 | + + ', ' + state.skipped_restricted + ' <?php echo esc_js(__('skipped (role-restricted)', 'mxchat')); ?>' | |
| 2319 | + + ', ' + state.failed + ' <?php echo esc_js(__('failed', 'mxchat')); ?>'); | |
| 2320 | + if (state.failed > 0 && state.last_error && state.status !== 'error') { | |
| 2321 | + bits.push('<?php echo esc_js(__('Last error:', 'mxchat')); ?> ' + state.last_error); | |
| 2322 | + } | |
| 2323 | + } | |
| 2324 | + statusEl.textContent = bits.join(' '); | |
| 2325 | + | |
| 2326 | + if (running && !pollTimer) { | |
| 2327 | + pollTimer = setInterval(function() { | |
| 2328 | + post('mxchat_vectorstore_import_status', function(res) { | |
| 2329 | + if (res && res.success) { render(res.data.state, res.data.mapped); } | |
| 2330 | + }); | |
| 2331 | + }, 3000); | |
| 2332 | + } else if (!running && pollTimer) { | |
| 2333 | + clearInterval(pollTimer); | |
| 2334 | + pollTimer = null; | |
| 2335 | + } | |
| 2336 | + } | |
| 2337 | + | |
| 2338 | + startBtn.addEventListener('click', function() { | |
| 2339 | + startBtn.disabled = true; | |
| 2340 | + statusEl.textContent = '<?php echo esc_js(__('Starting…', 'mxchat')); ?>'; | |
| 2341 | + post('mxchat_vectorstore_import_start', function(res) { | |
| 2342 | + startBtn.disabled = false; | |
| 2343 | + if (res && res.success) { render(res.data.state); } | |
| 2344 | + else { statusEl.textContent = (res && res.data && res.data.message) ? res.data.message : '<?php echo esc_js(__('Could not start the import.', 'mxchat')); ?>'; } | |
| 2345 | + }); | |
| 2346 | + }); | |
| 2347 | + resumeBtn.addEventListener('click', function() { | |
| 2348 | + post('mxchat_vectorstore_import_resume', function(res) { | |
| 2349 | + if (res && res.success) { render(res.data.state); } | |
| 2350 | + }); | |
| 2351 | + }); | |
| 2352 | + cancelBtn.addEventListener('click', function() { | |
| 2353 | + post('mxchat_vectorstore_import_cancel', function(res) { | |
| 2354 | + if (res && res.success) { render(res.data.state); } | |
| 2355 | + }); | |
| 2356 | + }); | |
| 2357 | + | |
| 2358 | + // Pick up an import already in flight when the page loads. | |
| 2359 | + post('mxchat_vectorstore_import_status', function(res) { | |
| 2360 | + if (res && res.success && res.data.state.status !== 'idle') { render(res.data.state, res.data.mapped); } | |
| 2361 | + }); | |
| 2362 | + })(); | |
| 2363 | + </script> | |
| 2364 | + <?php endif; ?> | |
| 1854 | 2365 | </div> |
| 1855 | 2366 | </div> |
| 1856 | 2367 | </div> |
| 1857 | 2368 | <?php |
| @@ -1900,8 +2411,20 @@ | ||
| 1900 | 2411 | <option value="unprocessed"><?php esc_html_e('Not In Knowledge Base', 'mxchat'); ?></option> |
| 1901 | 2412 | </select> |
| 1902 | 2413 | </div> |
| 1903 | 2414 | </div> |
| 2415 | + <?php | |
| 2416 | + // Shown only while Media is the selected type (plan 01010a). Media lists | |
| 2417 | + // just the files whose text MxChat can read; saying so here is clearer | |
| 2418 | + // than listing images and audio as rows that cannot be selected. | |
| 2419 | + ?> | |
| 2420 | + <div class="mxchat-kb-filter-note" id="mxchat-kb-media-note" hidden> | |
| 2421 | + <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"> | |
| 2422 | + <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path> | |
| 2423 | + <path d="M14 2v6h6"></path> | |
| 2424 | + </svg> | |
| 2425 | + <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> | |
| 2426 | + </div> | |
| 1904 | 2427 | <div class="mxchat-kb-content-selection"> |
| 1905 | 2428 | <div class="mxchat-kb-selection-header"> |
| 1906 | 2429 | <label> |
| 1907 | 2430 | <input type="checkbox" id="mxchat-kb-select-all"> |
| @@ -2196,83 +2719,15 @@ | ||
| 2196 | 2719 | 'use strict'; |
| 2197 | 2720 | |
| 2198 | 2721 | // Wait for DOM |
| 2199 | 2722 | document.addEventListener('DOMContentLoaded', function() { |
| 2200 | - initKnowledgeNavigation(); | |
| 2201 | - initMobileMenu(); | |
| 2723 | + // Tab navigation + mobile menu live in the shared shell script | |
| 2724 | + // (js/admin-sidebar.js), enqueued for this page by plan c192a4. | |
| 2202 | 2725 | initImportOptions(); |
| 2203 | 2726 | initCustomPostTypesToggle(); |
| 2204 | 2727 | // Sitemap detection is now initialized when user clicks the Sitemap Import option |
| 2205 | 2728 | }); |
| 2206 | 2729 | |
| 2207 | - function initKnowledgeNavigation() { | |
| 2208 | - const navLinks = document.querySelectorAll('.mxch-nav-link[data-target], .mxch-mobile-nav-link[data-target]'); | |
| 2209 | - const sections = document.querySelectorAll('.mxch-section'); | |
| 2210 | - | |
| 2211 | - function showSection(targetId) { | |
| 2212 | - // Hide all sections | |
| 2213 | - sections.forEach(section => section.classList.remove('active')); | |
| 2214 | - // Show target section | |
| 2215 | - const target = document.getElementById(targetId); | |
| 2216 | - if (target) { | |
| 2217 | - target.classList.add('active'); | |
| 2218 | - } | |
| 2219 | - // Update nav links | |
| 2220 | - navLinks.forEach(link => { | |
| 2221 | - link.classList.toggle('active', link.dataset.target === targetId); | |
| 2222 | - }); | |
| 2223 | - // Update URL hash | |
| 2224 | - history.replaceState(null, null, '#' + targetId); | |
| 2225 | - } | |
| 2226 | - | |
| 2227 | - navLinks.forEach(link => { | |
| 2228 | - link.addEventListener('click', function(e) { | |
| 2229 | - e.preventDefault(); | |
| 2230 | - const targetId = this.dataset.target; | |
| 2231 | - showSection(targetId); | |
| 2232 | - // Close mobile menu if open | |
| 2233 | - const mobileMenu = document.querySelector('.mxch-mobile-menu'); | |
| 2234 | - const overlay = document.querySelector('.mxch-mobile-overlay'); | |
| 2235 | - if (mobileMenu) mobileMenu.classList.remove('open'); | |
| 2236 | - if (overlay) overlay.classList.remove('open'); | |
| 2237 | - }); | |
| 2238 | - }); | |
| 2239 | - | |
| 2240 | - // Handle initial hash | |
| 2241 | - const hash = window.location.hash.substring(1); | |
| 2242 | - if (hash && document.getElementById(hash)) { | |
| 2243 | - showSection(hash); | |
| 2244 | - } | |
| 2245 | - } | |
| 2246 | - | |
| 2247 | - function initMobileMenu() { | |
| 2248 | - const menuBtn = document.querySelector('.mxch-mobile-menu-btn'); | |
| 2249 | - const closeBtn = document.querySelector('.mxch-mobile-menu-close'); | |
| 2250 | - const overlay = document.querySelector('.mxch-mobile-overlay'); | |
| 2251 | - const menu = document.querySelector('.mxch-mobile-menu'); | |
| 2252 | - | |
| 2253 | - if (menuBtn && menu) { | |
| 2254 | - menuBtn.addEventListener('click', function() { | |
| 2255 | - menu.classList.add('open'); | |
| 2256 | - if (overlay) overlay.classList.add('open'); | |
| 2257 | - }); | |
| 2258 | - } | |
| 2259 | - | |
| 2260 | - if (closeBtn && menu) { | |
| 2261 | - closeBtn.addEventListener('click', function() { | |
| 2262 | - menu.classList.remove('open'); | |
| 2263 | - if (overlay) overlay.classList.remove('open'); | |
| 2264 | - }); | |
| 2265 | - } | |
| 2266 | - | |
| 2267 | - if (overlay && menu) { | |
| 2268 | - overlay.addEventListener('click', function() { | |
| 2269 | - menu.classList.remove('open'); | |
| 2270 | - overlay.classList.remove('open'); | |
| 2271 | - }); | |
| 2272 | - } | |
| 2273 | - } | |
| 2274 | - | |
| 2275 | 2730 | function initImportOptions() { |
| 2276 | 2731 | const importBoxes = document.querySelectorAll('.mxchat-import-box'); |
| 2277 | 2732 | const urlInputArea = document.getElementById('mxchat-url-input-area'); |
| 2278 | 2733 | const contentInputArea = document.getElementById('mxchat-content-input-area'); |
| @@ -2519,13 +2974,23 @@ | ||
| 2519 | 2974 | if (saveSpin) saveSpin.style.display = 'none'; |
| 2520 | 2975 | saveBtn.disabled = false; |
| 2521 | 2976 | |
| 2522 | 2977 | if (resp.success) { |
| 2523 | - showNotice('Saved successfully!', 'success'); | |
| 2524 | - setTimeout(function() { | |
| 2525 | - closeModal(); | |
| 2526 | - window.location.reload(); | |
| 2527 | - }, 1000); | |
| 2978 | + if (currentEntry.dataSource === 'pinecone') { | |
| 2979 | + // Pinecone list reads are eventually consistent — the reloaded | |
| 2980 | + // table may show the old text for up to ~60 seconds. | |
| 2981 | + showNotice('Saved! Pinecone changes may take up to 60 seconds to appear — use "Refresh Entries" if the list still shows the old text.', 'success'); | |
| 2982 | + setTimeout(function() { | |
| 2983 | + closeModal(); | |
| 2984 | + window.location.reload(); | |
| 2985 | + }, 2500); | |
| 2986 | + } else { | |
| 2987 | + showNotice('Saved successfully!', 'success'); | |
| 2988 | + setTimeout(function() { | |
| 2989 | + closeModal(); | |
| 2990 | + window.location.reload(); | |
| 2991 | + }, 1000); | |
| 2992 | + } | |
| 2528 | 2993 | } else { |
| 2529 | 2994 | showNotice((resp.data && resp.data.message) || 'Save failed.', 'error'); |
| 2530 | 2995 | } |
| 2531 | 2996 | }) |