PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / trunk
MxChat – AI Chatbot & Content Generation for WordPress vtrunk
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 2.0.3 2.0.4 2.0.5 2.0.6 All 152 releases
← All changes | includes/admin-knowledge-page.php +668 -97 3.2.2trunk View file →
@@ -73,9 +73,9 @@
73 73 <span><?php esc_html_e('Auto-Sync', 'mxchat'); ?></span>
74 74 </button>
75 75 <button class="mxch-mobile-nav-link" data-target="chunking">
76 76 <svg 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"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/></svg>
77 - <span><?php esc_html_e('Content Chunking', 'mxchat'); ?></span>
77 + <span><?php esc_html_e('Chunking & Retrieval', 'mxchat'); ?></span>
78 78 </button>
79 79 <button class="mxch-mobile-nav-link" data-target="role-restrictions">
80 80 <svg 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="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>
81 81 <span><?php esc_html_e('Role Restrictions', 'mxchat'); ?></span>
@@ -172,9 +172,9 @@
172 172 <button class="mxch-nav-link" data-target="chunking">
173 173 <span class="mxch-nav-link-icon">
174 174 <svg 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"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/></svg>
175 175 </span>
176 - <span class="mxch-nav-link-text"><?php esc_html_e('Content Chunking', 'mxchat'); ?></span>
176 + <span class="mxch-nav-link-text"><?php esc_html_e('Chunking & Retrieval', 'mxchat'); ?></span>
177 177 </button>
178 178 </div>
179 179
180 180 <div class="mxch-nav-item" data-section="role-restrictions">
@@ -275,8 +275,11 @@
275 275
276 276 // Render the Edit Entry Modal
277 277 mxchat_render_edit_entry_modal();
278 278
279 + // Render the read-only Knowledge Inspector modal (plan-d8cb4b)
280 + mxchat_render_inspect_entry_modal();
281 +
279 282 // Render the navigation JavaScript
280 283 mxchat_render_knowledge_page_scripts();
281 284 }
282 285
@@ -552,8 +555,30 @@
552 555 <h4><?php esc_html_e('PDF Upload', 'mxchat'); ?></h4>
553 556 <p><?php esc_html_e('Upload a PDF file from your computer.', 'mxchat'); ?></p>
554 557 </div>
555 558 </button>
559 +
560 + <!-- Document File Upload Option (plan 0485e5) -->
561 + <button type="button" class="mxchat-import-box" data-option="document-upload" data-type="document-upload">
562 + <div class="mxchat-import-icon">
563 + <span class="dashicons dashicons-media-text"></span>
564 + </div>
565 + <div class="mxchat-import-content">
566 + <h4><?php esc_html_e('Document Upload', 'mxchat'); ?></h4>
567 + <p><?php esc_html_e('Upload a Word document, text, or Markdown file (.docx, .txt, .md).', 'mxchat'); ?></p>
568 + </div>
569 + </button>
570 +
571 + <!-- YouTube Video Import Option -->
572 + <button type="button" class="mxchat-import-box" data-option="youtube" data-type="youtube">
573 + <div class="mxchat-import-icon">
574 + <span class="dashicons dashicons-youtube"></span>
575 + </div>
576 + <div class="mxchat-import-content">
577 + <h4><?php esc_html_e('YouTube', 'mxchat'); ?></h4>
578 + <p><?php esc_html_e('Index a video so the chat can surface it as a playable embed.', 'mxchat'); ?></p>
579 + </div>
580 + </button>
556 581 </div>
557 582
558 583 <!-- Detected Sitemaps Section (hidden by default, shown when Sitemap Import is clicked) -->
559 584 <div id="mxchat-detected-sitemaps" class="mxchat-detected-sitemaps" style="display: none;">
@@ -655,8 +680,72 @@
655 680 <?php esc_html_e('Import PDF', 'mxchat'); ?>
656 681 </button>
657 682 </form>
658 683 </div>
684 +
685 + <div class="mxchat-import-input-area" id="mxchat-document-upload-area" style="display: none; margin-top: 20px;">
686 + <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">
687 + <?php wp_nonce_field('mxchat_submit_document_file_action', 'mxchat_submit_document_file_nonce'); ?>
688 + <?php if ($multibot_active && $current_bot_id !== 'default') : ?>
689 + <input type="hidden" name="bot_id" value="<?php echo esc_attr($current_bot_id); ?>">
690 + <?php endif; ?>
691 + <div class="mxch-field">
692 + <input type="file" name="document_file" id="mxchat-document-file-input" accept=".docx,.txt,.md" required>
693 + </div>
694 + <p class="mxch-field-description">
695 + <?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 + </p>
697 + <button type="submit" name="submit_document_file" class="mxch-btn mxch-btn-primary">
698 + <?php esc_html_e('Import Document', 'mxchat'); ?>
699 + </button>
700 + </form>
701 + </div>
702 +
703 + <?php
704 + // Prefill state: set when an auto-import found no transcript — the
705 + // handler bounced back here so the admin can augment the entry with
706 + // a manual description (re-importing the same URL updates the row).
707 + $yt_prefill = isset($_GET['mxchat_yt_prefill']) && $_GET['mxchat_yt_prefill'] === '1';
708 + $yt_prefill_url = $yt_prefill && isset($_GET['yt_url']) ? esc_url_raw(rawurldecode(wp_unslash($_GET['yt_url']))) : '';
709 + $yt_prefill_title = $yt_prefill && isset($_GET['yt_title']) ? sanitize_text_field(rawurldecode(wp_unslash($_GET['yt_title']))) : '';
710 + ?>
711 + <div class="mxchat-import-input-area" id="mxchat-youtube-input-area" style="display: none; margin-top: 20px;">
712 + <form id="mxchat-youtube-form" method="post" action="<?php echo esc_url(admin_url('admin-post.php?action=mxchat_submit_youtube')); ?>"<?php echo $yt_prefill ? ' data-yt-prefill="1"' : ''; ?>>
713 + <?php wp_nonce_field('mxchat_submit_youtube_action', 'mxchat_submit_youtube_nonce'); ?>
714 + <?php if ($multibot_active && $current_bot_id !== 'default') : ?>
715 + <input type="hidden" name="bot_id" value="<?php echo esc_attr($current_bot_id); ?>">
716 + <?php endif; ?>
717 + <div class="mxch-field">
718 + <input type="url" name="youtube_url" id="mxchat-youtube-url" class="mxch-input" placeholder="<?php esc_attr_e('Paste a YouTube video URL (watch, youtu.be, or Shorts link)', 'mxchat'); ?>" required value="<?php echo esc_attr($yt_prefill_url); ?>">
719 + </div>
720 + <div class="mxch-field">
721 + <span class="mxch-field-label"><?php esc_html_e('How should this video be described for matching?', 'mxchat'); ?></span>
722 + <div style="display: flex; flex-direction: column; gap: 6px; margin-top: 8px;">
723 + <label style="display: flex; align-items: baseline; gap: 8px; cursor: pointer;">
724 + <input type="radio" name="youtube_description_mode" value="auto" <?php checked(!$yt_prefill); ?>>
725 + <span>
726 + <strong><?php esc_html_e('Auto-fetch', 'mxchat'); ?></strong>
727 + <span class="mxch-field-description" style="display: block; margin: 2px 0 0;"><?php esc_html_e('We pull the video\'s title, channel, and captions (when available) to describe it.', 'mxchat'); ?></span>
728 + </span>
729 + </label>
730 + <label style="display: flex; align-items: baseline; gap: 8px; cursor: pointer;">
731 + <input type="radio" name="youtube_description_mode" value="manual" <?php checked($yt_prefill); ?>>
732 + <span>
733 + <strong><?php esc_html_e('Write my own', 'mxchat'); ?></strong>
734 + <span class="mxch-field-description" style="display: block; margin: 2px 0 0;"><?php esc_html_e('You write the description the chatbot matches against — best for curated guides.', 'mxchat'); ?></span>
735 + </span>
736 + </label>
737 + </div>
738 + </div>
739 + <div class="mxch-field" id="mxchat-youtube-description-field" style="<?php echo $yt_prefill ? '' : 'display: none;'; ?>">
740 + <textarea name="youtube_description" id="mxchat-youtube-description" class="mxch-textarea" rows="5" placeholder="<?php esc_attr_e('Describe what this video covers and the questions it answers...', 'mxchat'); ?>"><?php echo esc_textarea($yt_prefill_title !== '' ? $yt_prefill_title . "\n\n" : ''); ?></textarea>
741 + <p class="mxch-field-description"><?php esc_html_e('This text is what gets matched against visitor questions. Importing the same video URL again updates its existing entry.', 'mxchat'); ?></p>
742 + </div>
743 + <button type="submit" name="submit_youtube" value="1" class="mxch-btn mxch-btn-primary">
744 + <?php esc_html_e('Import Video', 'mxchat'); ?>
745 + </button>
746 + </form>
747 + </div>
659 748 <?php endif; ?>
660 749 </div>
661 750 </div>
662 751 </div>
@@ -989,10 +1078,19 @@
989 1078 <span style="color: var(--mxch-text-muted);"><?php esc_html_e('Manual Content', 'mxchat'); ?></span>
990 1079 <?php endif; ?>
991 1080 </td>
992 1081 <td class="mxchat-actions-cell" style="padding: 12px 16px; white-space: nowrap;">
993 - <?php if ($data_source !== 'pinecone') : ?>
994 1082 <button type="button"
1083 + class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-inspect-entry-btn"
1084 + data-source-url="<?php echo esc_attr($source_url); ?>"
1085 + data-entry-id="<?php echo esc_attr($first_prompt->id); ?>"
1086 + data-data-source="<?php echo esc_attr($data_source); ?>"
1087 + data-bot-id="<?php echo esc_attr($current_bot_id); ?>"
1088 + data-nonce="<?php echo wp_create_nonce('mxchat_inspect_entry_nonce'); ?>"
1089 + title="<?php esc_attr_e('View indexed content', 'mxchat'); ?>">
1090 + <span class="dashicons dashicons-visibility" style="font-size: 14px;"></span>
1091 + </button>
1092 + <button type="button"
995 1093 class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-edit-entry-btn"
996 1094 data-source-url="<?php echo esc_attr($source_url); ?>"
997 1095 data-entry-id="<?php echo esc_attr($first_prompt->id); ?>"
998 1096 data-data-source="<?php echo esc_attr($data_source); ?>"
@@ -1000,9 +1098,8 @@
1000 1098 data-nonce="<?php echo wp_create_nonce('mxchat_edit_entry_nonce'); ?>"
1001 1099 title="<?php esc_attr_e('Edit content', 'mxchat'); ?>">
1002 1100 <span class="dashicons dashicons-edit" style="font-size: 14px;"></span>
1003 1101 </button>
1004 - <?php endif; ?>
1005 1102 <button type="button"
1006 1103 class="mxch-btn mxch-btn-ghost mxch-btn-sm delete-button-group"
1007 1104 data-source-url="<?php echo esc_attr($source_url); ?>"
1008 1105 data-chunk-count="<?php echo esc_attr($chunk_count); ?>"
@@ -1139,10 +1236,19 @@
1139 1236 <span style="color: var(--mxch-text-muted);"><?php esc_html_e('Manual', 'mxchat'); ?></span>
1140 1237 <?php endif; ?>
1141 1238 </td>
1142 1239 <td style="padding: 12px 16px; white-space: nowrap;">
1143 - <?php if ($data_source !== 'pinecone') : ?>
1144 1240 <button type="button"
1241 + class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-inspect-entry-btn"
1242 + data-source-url="<?php echo esc_attr($prompt->source_url ?? ''); ?>"
1243 + data-entry-id="<?php echo esc_attr($prompt->id); ?>"
1244 + data-data-source="<?php echo esc_attr($data_source); ?>"
1245 + data-bot-id="<?php echo esc_attr($current_bot_id); ?>"
1246 + data-nonce="<?php echo wp_create_nonce('mxchat_inspect_entry_nonce'); ?>"
1247 + title="<?php esc_attr_e('View indexed content', 'mxchat'); ?>">
1248 + <span class="dashicons dashicons-visibility" style="font-size: 14px;"></span>
1249 + </button>
1250 + <button type="button"
1145 1251 class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-edit-entry-btn"
1146 1252 data-source-url="<?php echo esc_attr($prompt->source_url ?? ''); ?>"
1147 1253 data-entry-id="<?php echo esc_attr($prompt->id); ?>"
1148 1254 data-data-source="<?php echo esc_attr($data_source); ?>"
@@ -1150,9 +1256,8 @@
1150 1256 data-nonce="<?php echo wp_create_nonce('mxchat_edit_entry_nonce'); ?>"
1151 1257 title="<?php esc_attr_e('Edit content', 'mxchat'); ?>">
1152 1258 <span class="dashicons dashicons-edit" style="font-size: 14px;"></span>
1153 1259 </button>
1154 - <?php endif; ?>
1155 1260 <?php if ($data_source === 'pinecone') : ?>
1156 1261 <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);">
1157 1262 <span class="dashicons dashicons-trash" style="font-size: 14px;"></span>
1158 1263 </button>
@@ -1246,8 +1351,19 @@
1246 1351 <span style="font-weight: 500;"><?php esc_html_e('Auto-sync Pages', 'mxchat'); ?></span>
1247 1352 </div>
1248 1353 </div>
1249 1354
1355 + <div class="mxch-field" style="margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--mxch-card-border);">
1356 + <div style="display: flex; align-items: center; gap: 12px;">
1357 + <label class="mxchat-toggle-switch">
1358 + <input type="checkbox" name="mxchat_auto_sync_acf_pdfs" class="mxchat-autosave-field" value="1" data-nonce="<?php echo wp_create_nonce('mxchat_prompts_setting_nonce'); ?>" <?php checked(get_option('mxchat_auto_sync_acf_pdfs', '0'), '1'); ?>>
1359 + <span class="mxchat-toggle-slider"></span>
1360 + </label>
1361 + <span style="font-weight: 500;"><?php esc_html_e('Extract text from PDFs in ACF fields on save', 'mxchat'); ?></span>
1362 + </div>
1363 + <p class="mxch-field-description" style="margin-top: 8px;"><?php esc_html_e('When ON, editor saves re-extract every PDF referenced in ACF fields. Default OFF — saves stay fast and don\'t re-parse the same PDFs on every edit. The manual content selector has its own per-batch checkbox; this setting only controls the auto-sync path.', 'mxchat'); ?></p>
1364 + </div>
1365 +
1250 1366 <div style="margin-top: 24px;">
1251 1367 <button id="mxchat-custom-post-types-toggle" class="mxch-btn mxch-btn-secondary">
1252 1368 <?php esc_html_e('Advanced Custom Post Sync Settings', 'mxchat'); ?>
1253 1369 <span style="margin-left: 5px;">▼</span>
@@ -1293,13 +1409,16 @@
1293 1409 $chunk_size = $chunking_settings['chunk_size'];
1294 1410 ?>
1295 1411 <div id="chunking" class="mxch-section">
1296 1412 <div class="mxch-content-header">
1297 - <h1 class="mxch-content-title"><?php esc_html_e('Content Chunking', 'mxchat'); ?></h1>
1298 - <p class="mxch-content-subtitle"><?php esc_html_e('Split large content into smaller segments for more accurate semantic search.', 'mxchat'); ?></p>
1413 + <h1 class="mxch-content-title"><?php esc_html_e('Chunking & Retrieval', 'mxchat'); ?></h1>
1414 + <p class="mxch-content-subtitle"><?php esc_html_e('Control how content is split for indexing and how the knowledge base is searched.', 'mxchat'); ?></p>
1299 1415 </div>
1300 1416
1301 1417 <div class="mxch-card">
1418 + <div class="mxch-card-header">
1419 + <h2 class="mxch-card-title"><?php esc_html_e('Chunking', 'mxchat'); ?></h2>
1420 + </div>
1302 1421 <div class="mxch-card-body mxchat-autosave-section">
1303 1422 <div class="mxch-notice mxch-notice-info" style="margin-bottom: 20px;">
1304 1423 <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>
1305 1424 <span><?php esc_html_e('Chunking improves retrieval quality for long documents. All chunks are reassembled before sending to the AI. Only applies to new submissions.', 'mxchat'); ?></span>
@@ -1321,8 +1440,83 @@
1321 1440 <p class="mxch-field-description"><?php esc_html_e('Recommended: 4000 characters (~1000 tokens). Range: 1000-10000. Larger chunks preserve more context.', 'mxchat'); ?></p>
1322 1441 </div>
1323 1442 </div>
1324 1443 </div>
1444 +
1445 + <?php
1446 + // Retrieval tuning (plan 11720c) — the hybrid keyword boost moved here
1447 + // from Settings → Behavior: it is KB retrieval tuning, so it lives with
1448 + // its natural siblings. SAME option key and save transport as before —
1449 + // the name routes to the mxchat_save_setting handler, whose
1450 + // mxchat_hybrid_keyword_toggle case still runs capability detection.
1451 + ?>
1452 + <div class="mxch-card">
1453 + <div class="mxch-card-header">
1454 + <h2 class="mxch-card-title"><?php esc_html_e('Retrieval', 'mxchat'); ?></h2>
1455 + </div>
1456 + <div class="mxch-card-body mxchat-autosave-section">
1457 + <div class="mxch-field">
1458 + <div style="display: flex; align-items: center; gap: 12px;">
1459 + <label class="mxchat-toggle-switch">
1460 + <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 + <span class="mxchat-toggle-slider"></span>
1462 + </label>
1463 + <span style="font-weight: 500;"><?php esc_html_e('Hybrid keyword boost (WP-DB knowledge base)', 'mxchat'); ?></span>
1464 + </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>
1467 + </div>
1468 + </div>
1469 + </div>
1470 +
1471 + <?php
1472 + // Video cards (plan f52492). Lives on the Knowledge screen because that
1473 + // is where the owner imported the video in the first place, and beside
1474 + // Retrieval because it is a retrieval-confidence question. Standalone
1475 + // options — see the mxchat_video_embed_* cases in class-ajax-handler.php.
1476 + $video_embed_enabled = MxChat_Utils::video_embed_enabled();
1477 + $video_embed_threshold = (int) round(MxChat_Utils::video_embed_threshold() * 100);
1478 + $mxchat_core_options = get_option('mxchat_options', array());
1479 + $site_threshold = isset($mxchat_core_options['similarity_threshold'])
1480 + ? (int) $mxchat_core_options['similarity_threshold']
1481 + : 35;
1482 + ?>
1483 + <div class="mxch-card">
1484 + <div class="mxch-card-header">
1485 + <h2 class="mxch-card-title"><?php esc_html_e('Video Cards', 'mxchat'); ?></h2>
1486 + </div>
1487 + <div class="mxch-card-body mxchat-autosave-section">
1488 + <div class="mxch-field" style="margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid var(--mxch-card-border);">
1489 + <div style="display: flex; align-items: center; gap: 12px;">
1490 + <label class="mxchat-toggle-switch">
1491 + <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); ?>>
1492 + <span class="mxchat-toggle-slider"></span>
1493 + </label>
1494 + <span style="font-weight: 500;"><?php esc_html_e('Show a video card when a YouTube source answers the question', 'mxchat'); ?></span>
1495 + </div>
1496 + <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>
1497 + </div>
1498 +
1499 + <div class="mxch-field" id="mxchat-video-embed-threshold-field" style="<?php echo $video_embed_enabled ? '' : 'display: none;'; ?>">
1500 + <label class="mxch-field-label" for="mxchat_video_embed_threshold"><?php esc_html_e('Video Card Match Threshold (%)', 'mxchat'); ?></label>
1501 + <?php // Slider matching the site-wide Similarity Threshold exactly
1502 + // (plan 7afd54): same .slider-container / .range-slider /
1503 + // .range-value markup; the shared admin JS live-updates the
1504 + // <id>_value span on input and autosaves on change (once per
1505 + // drag release, so no request storm). Range/default/clamp
1506 + // unchanged — presentation only. ?>
1507 + <div class="slider-container">
1508 + <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">
1509 + <span id="mxchat_video_embed_threshold_value" class="range-value"><?php echo esc_html((int) $video_embed_threshold); ?></span>
1510 + </div>
1511 + <p class="mxch-field-description"><?php
1512 + /* translators: %d is the site-wide Similarity Threshold percentage. */
1513 + 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);
1514 + ?></p>
1515 + <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>
1516 + </div>
1517 + </div>
1518 + </div>
1325 1519 </div>
1326 1520 <?php
1327 1521 }
1328 1522
@@ -1355,10 +1549,11 @@
1355 1549
1356 1550 <h4 style="margin: 0 0 16px 0;"><?php esc_html_e('Add Tag-Role Mapping', 'mxchat'); ?></h4>
1357 1551 <div style="display: flex; gap: 15px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 24px;">
1358 1552 <div class="mxch-field" style="flex: 1; min-width: 200px; margin-bottom: 0;">
1359 - <label class="mxch-field-label" for="mxchat-tag-input"><?php esc_html_e('Tag Name', 'mxchat'); ?></label>
1360 - <input type="text" id="mxchat-tag-input" class="mxch-input" placeholder="<?php esc_attr_e('e.g., premium, members-only', 'mxchat'); ?>">
1553 + <label class="mxch-field-label" for="mxchat-tag-input"><?php esc_html_e('Tag (name or slug)', 'mxchat'); ?></label>
1554 + <input type="text" id="mxchat-tag-input" class="mxch-input" placeholder="<?php esc_attr_e('e.g., Premium Content or premium-content', 'mxchat'); ?>">
1555 + <span class="mxch-field-hint"><?php esc_html_e('Enter an existing post tag by its display name or its slug.', 'mxchat'); ?></span>
1361 1556 </div>
1362 1557 <div class="mxch-field" style="flex: 1; min-width: 200px; margin-bottom: 0;">
1363 1558 <label class="mxch-field-label" for="mxchat-role-select"><?php esc_html_e('Required Role', 'mxchat'); ?></label>
1364 1559 <select id="mxchat-role-select" class="mxch-select">
@@ -1421,8 +1616,23 @@
1421 1616 </div>
1422 1617
1423 1618 <div class="mxch-card">
1424 1619 <div class="mxch-card-body mxchat-autosave-section">
1620 + <?php
1621 + // Install-level ACF→PDF import extraction (plan 11720c) — moved
1622 + // here from a per-import checkbox in the content-selector modal.
1623 + // Default OFF, matching its own "recommended only if…" guidance.
1624 + ?>
1625 + <div class="mxch-field" style="margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid var(--mxch-card-border);">
1626 + <div style="display: flex; align-items: center; gap: 12px;">
1627 + <label class="mxchat-toggle-switch">
1628 + <input type="checkbox" name="mxchat_acf_pdf_extraction" id="mxchat_acf_pdf_extraction" class="mxchat-autosave-field" value="on" <?php checked(get_option('mxchat_acf_pdf_extraction', '0'), '1'); ?>>
1629 + <span class="mxchat-toggle-slider"></span>
1630 + </label>
1631 + <span style="font-weight: 500;"><?php esc_html_e('Extract text from PDFs linked in ACF File/Image fields during imports', 'mxchat'); ?></span>
1632 + </div>
1633 + <p class="mxch-field-description" style="margin-top: 8px;"><?php esc_html_e('Applies to WordPress Content imports. Adds 200-500ms per post and ~30 KB to each knowledge base entry. Recommended only if your ACF setup uses PDF attachments for primary content. Editor-save extraction has its own toggle under Auto-Sync.', 'mxchat'); ?></p>
1634 + </div>
1425 1635 <?php if (!function_exists('acf_get_field_groups')): ?>
1426 1636 <div class="mxch-notice mxch-notice-info">
1427 1637 <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>
1428 1638 <span><?php esc_html_e('Advanced Custom Fields (ACF) plugin is not detected. Install and activate ACF to use this feature.', 'mxchat'); ?></span>
@@ -1437,30 +1647,55 @@
1437 1647 </div>
1438 1648 <?php else: ?>
1439 1649 <div class="mxch-notice mxch-notice-info" style="margin-bottom: 20px;">
1440 1650 <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>
1441 - <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>
1651 + <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>
1442 1652 </div>
1443 1653
1444 - <?php foreach ($all_acf_fields as $group_title => $fields): ?>
1445 - <div class="mxchat-acf-field-group" style="margin-bottom: 24px;">
1446 - <h4 style="margin: 0 0 12px 0; color: var(--mxch-text-primary); font-weight: 600;">
1447 - <?php echo esc_html($group_title); ?>
1448 - </h4>
1654 + <?php foreach ($all_acf_fields as $group_key => $group):
1655 + $fields = $group['fields'];
1656 + // Group toggle state derives from the per-field state —
1657 + // never stored on its own (plan bf57e0).
1658 + $excluded_count = 0;
1659 + foreach ($fields as $field) {
1660 + if (in_array($field['key'], $excluded_fields, true) || in_array($field['name'], $excluded_fields, true)) {
1661 + $excluded_count++;
1662 + }
1663 + }
1664 + $group_all_included = ($excluded_count === 0);
1665 + $group_partial = ($excluded_count > 0 && $excluded_count < count($fields));
1666 + ?>
1667 + <div class="mxchat-acf-field-group" style="margin-bottom: 24px;" data-mxchat-acf-group="<?php echo esc_attr($group_key); ?>">
1668 + <div style="display: flex; align-items: center; justify-content: space-between; margin: 0 0 12px 0;">
1669 + <h4 style="margin: 0; color: var(--mxch-text-primary); font-weight: 600;">
1670 + <?php echo esc_html($group['title']); ?>
1671 + </h4>
1672 + <label class="mxchat-toggle-switch" title="<?php esc_attr_e('Include or exclude every field in this group', 'mxchat'); ?>">
1673 + <input type="checkbox"
1674 + class="mxchat-acf-group-toggle"
1675 + data-group-key="<?php echo esc_attr($group_key); ?>"
1676 + data-nonce="<?php echo wp_create_nonce('mxchat_prompts_setting_nonce'); ?>"
1677 + <?php if ($group_partial): ?>data-indeterminate="1"<?php endif; ?>
1678 + <?php checked($group_all_included, true); ?>>
1679 + <span class="mxchat-toggle-slider"></span>
1680 + </label>
1681 + </div>
1449 1682 <div style="background: #f8fafc; border-radius: var(--mxch-radius-md); padding: 16px;">
1450 1683 <?php foreach ($fields as $field):
1451 - $field_name = $field['name'];
1452 - $is_enabled = !in_array($field_name, $excluded_fields);
1684 + // Toggles identify fields by ACF field KEY — names are shared
1685 + // across groups and collide (plan 30e81f). Legacy name entries
1686 + // (group inactive at migration time) still count as excluded.
1687 + $is_enabled = !in_array($field['key'], $excluded_fields, true) && !in_array($field['name'], $excluded_fields, true);
1453 1688 ?>
1454 1689 <div style="display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #e2e8f0;">
1455 1690 <div>
1456 1691 <span style="font-weight: 500;"><?php echo esc_html($field['label']); ?></span>
1457 - <span style="color: var(--mxch-text-muted); font-size: 12px; margin-left: 8px;">(<?php echo esc_html($field_name); ?>)</span>
1692 + <span style="color: var(--mxch-text-muted); font-size: 12px; margin-left: 8px;">(<?php echo esc_html($field['name']); ?>)</span>
1458 1693 <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>
1459 1694 </div>
1460 1695 <label class="mxchat-toggle-switch">
1461 1696 <input type="checkbox"
1462 - name="mxchat_acf_field_<?php echo esc_attr($field_name); ?>"
1697 + name="mxchat_acf_field_<?php echo esc_attr($field['key']); ?>"
1463 1698 class="mxchat-autosave-field"
1464 1699 value="on"
1465 1700 data-nonce="<?php echo wp_create_nonce('mxchat_prompts_setting_nonce'); ?>"
1466 1701 <?php checked($is_enabled, true); ?>>
@@ -1497,8 +1732,28 @@
1497 1732 <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>
1498 1733 <span><?php esc_html_e('Enter post meta keys to include in embeddings. This is useful for OptionTree fields, theme meta boxes, or any custom post meta that is not managed by ACF.', 'mxchat'); ?></span>
1499 1734 </div>
1500 1735
1736 + <!-- Meta-key discovery scanner (plan-mxchat-20260709-fe8e4e): mirror the ACF picker's
1737 + discover-for-you UX for non-ACF meta, so owners click keys instead of typing them blind. -->
1738 + <div class="mxch-field mxchat-meta-scan">
1739 + <label class="mxch-field-label"><?php esc_html_e('Discover meta keys', 'mxchat'); ?></label>
1740 + <p class="mxch-field-description" style="margin-top: 0;">
1741 + <?php esc_html_e('Scan your published content for custom meta keys, then click any you want to include. This gives non-ACF meta the same discover-and-click experience as the ACF picker.', 'mxchat'); ?>
1742 + </p>
1743 + <div class="mxchat-meta-scan-controls">
1744 + <button type="button" id="mxchat-scan-meta-btn" class="mxch-btn mxch-btn-secondary" data-nonce="<?php echo esc_attr(wp_create_nonce('mxchat_prompts_setting_nonce')); ?>">
1745 + <svg 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"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
1746 + <span class="mxchat-scan-label"><?php esc_html_e('Scan my content for meta keys', 'mxchat'); ?></span>
1747 + </button>
1748 + <label class="mxchat-meta-scan-internal">
1749 + <input type="checkbox" id="mxchat-scan-internal">
1750 + <?php esc_html_e('Include internal keys (underscore-prefixed)', 'mxchat'); ?>
1751 + </label>
1752 + </div>
1753 + <div id="mxchat-meta-scan-results" class="mxchat-meta-scan-results" aria-live="polite"></div>
1754 + </div>
1755 +
1501 1756 <div class="mxch-field">
1502 1757 <label class="mxch-field-label" for="mxchat_custom_meta_whitelist">
1503 1758 <?php esc_html_e('Meta Key Whitelist', 'mxchat'); ?>
1504 1759 </label>
@@ -1511,9 +1766,9 @@
1511 1766 data-nonce="<?php echo wp_create_nonce('mxchat_prompts_setting_nonce'); ?>"
1512 1767 style="font-family: monospace;"
1513 1768 ><?php echo esc_textarea($whitelist); ?></textarea>
1514 1769 <p class="mxch-field-description">
1515 - <?php esc_html_e('Enter one meta key per line. These fields will be appended to the content during embedding. Only string values are included.', 'mxchat'); ?>
1770 + <?php esc_html_e('Enter one meta key per line. These fields will be appended to the content during embedding. Text values are added as-is; array or repeater values are flattened into a comma-separated list. Empty values are skipped.', 'mxchat'); ?>
1516 1771 </p>
1517 1772 </div>
1518 1773
1519 1774 <div style="margin-top: 20px; padding: 16px; background: #f8fafc; border-radius: var(--mxch-radius-md);">
@@ -1520,9 +1775,9 @@
1520 1775 <h4 style="margin: 0 0 12px 0; font-size: 14px;"><?php esc_html_e('How to find meta keys:', 'mxchat'); ?></h4>
1521 1776 <ul style="margin: 0; padding-left: 20px; color: var(--mxch-text-secondary); font-size: 13px;">
1522 1777 <li><?php esc_html_e('Check your theme documentation for meta key names', 'mxchat'); ?></li>
1523 1778 <li><?php esc_html_e('Look in the wp_postmeta database table', 'mxchat'); ?></li>
1524 - <li><?php esc_html_e('Use a plugin like "Show Post Meta" to view meta keys on any post', 'mxchat'); ?></li>
1779 + <li><?php esc_html_e('Use the Scan my content for meta keys button above to discover the keys on your published content automatically', 'mxchat'); ?></li>
1525 1780 <li><?php esc_html_e('Meta keys starting with underscore (_) are usually hidden/internal', 'mxchat'); ?></li>
1526 1781 </ul>
1527 1782 </div>
1528 1783 </div>
@@ -1603,8 +1858,16 @@
1603 1858 </label>
1604 1859 <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">
1605 1860 <p class="mxch-field-description"><?php esc_html_e('The hostname from your Pinecone index URL (exclude https://). Found in index details.', 'mxchat'); ?></p>
1606 1861 </div>
1862 +
1863 + <div class="mxch-field">
1864 + <label class="mxch-field-label" for="mxchat_pinecone_top_k">
1865 + <?php esc_html_e('Results Per Query (topK)', 'mxchat'); ?>
1866 + </label>
1867 + <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">
1868 + <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>
1869 + </div>
1607 1870 </div>
1608 1871
1609 1872 <?php submit_button(__('Save Pinecone Settings', 'mxchat'), 'primary', 'submit', true, array('class' => 'mxch-btn mxch-btn-primary')); ?>
1610 1873 </form>
@@ -1621,12 +1884,16 @@
1621 1884 $vectorstore_options = get_option('mxchat_openai_vectorstore_options', array());
1622 1885 $use_vectorstore = $vectorstore_options['mxchat_use_openai_vectorstore'] ?? '0';
1623 1886 $vectorstore_ids = $vectorstore_options['mxchat_vectorstore_ids'] ?? '';
1624 1887 $max_results = $vectorstore_options['mxchat_vectorstore_max_results'] ?? 5;
1888 + $sync_enabled = $vectorstore_options['mxchat_vectorstore_sync_enabled'] ?? '0';
1889 + $sync_store_id = $vectorstore_options['mxchat_vectorstore_sync_store_id'] ?? '';
1890 + $sync_config = class_exists('MxChat_Vectorstore_Manager') ? MxChat_Vectorstore_Manager::get_sync_config('default') : array('enabled' => false, 'store_id' => '');
1891 + $mapped_count = class_exists('MxChat_Vectorstore_Manager') ? MxChat_Vectorstore_Manager::mapped_file_count() : 0;
1625 1892
1626 1893 // Get current chat model to check compatibility
1627 1894 $mxchat_options = get_option('mxchat_options', array());
1628 - $current_model = $mxchat_options['model'] ?? 'gpt-5.1-chat-latest';
1895 + $current_model = $mxchat_options['model'] ?? 'gpt-5.6-sol';
1629 1896 $is_openai_model = preg_match('/^(gpt-|o1-|o3-)/', $current_model);
1630 1897 ?>
1631 1898 <div id="openai-vectorstore" class="mxch-section">
1632 1899 <div class="mxch-content-header">
@@ -1637,9 +1904,9 @@
1637 1904 <div class="mxch-card">
1638 1905 <div class="mxch-card-body">
1639 1906 <div class="mxch-notice mxch-notice-info" style="margin-bottom: 20px;">
1640 1907 <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>
1641 - <span><strong><?php esc_html_e('Requires OpenAI Chat Model.', 'mxchat'); ?></strong> <?php esc_html_e('Vector Store search only works with OpenAI models (gpt-5.1-chat-latest, gpt-5-mini, etc.). Create Vector Stores in your OpenAI Dashboard.', 'mxchat'); ?></span>
1908 + <span><strong><?php esc_html_e('Requires OpenAI Chat Model.', 'mxchat'); ?></strong> <?php esc_html_e('Vector Store search only works with OpenAI models (gpt-5.6-sol, gpt-5.6-terra, etc.). Create Vector Stores in your OpenAI Dashboard.', 'mxchat'); ?></span>
1642 1909 </div>
1643 1910
1644 1911 <?php if (!$is_openai_model && $use_vectorstore === '1'): ?>
1645 1912 <div class="mxch-notice mxch-notice-warning" style="margin-bottom: 20px;">
@@ -1692,10 +1959,143 @@
1692 1959 <p class="mxch-field-description"><?php esc_html_e('Maximum number of content chunks to retrieve from the Vector Store.', 'mxchat'); ?></p>
1693 1960 </div>
1694 1961 </div>
1695 1962
1963 + <div class="mxch-field" style="border-top: 1px solid var(--mxch-border, #e2e4e7); padding-top: 20px; margin-top: 4px;">
1964 + <div style="display: flex; align-items: center; gap: 12px; margin-bottom: 8px;">
1965 + <label class="mxchat-toggle-switch">
1966 + <input type="checkbox" name="mxchat_openai_vectorstore_options[mxchat_vectorstore_sync_enabled]" value="1" <?php checked($sync_enabled, '1'); ?> id="mxchat_vectorstore_sync_enabled">
1967 + <span class="mxchat-toggle-slider"></span>
1968 + </label>
1969 + <span style="font-weight: 500;"><?php esc_html_e('Sync Knowledge Base to Vector Store', 'mxchat'); ?></span>
1970 + </div>
1971 + <p class="mxch-field-description" style="margin-bottom: 16px;">
1972 + <?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'); ?>
1973 + </p>
1974 +
1975 + <label class="mxch-field-label" for="mxchat_vectorstore_sync_store_id">
1976 + <?php esc_html_e('Sync Target Vector Store ID', 'mxchat'); ?>
1977 + </label>
1978 + <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'); ?>">
1979 + <p class="mxch-field-description">
1980 + <?php esc_html_e('Leave blank to use the first Vector Store ID above. Syncing writes to exactly one store.', 'mxchat'); ?>
1981 + </p>
1982 + </div>
1983 +
1696 1984 <?php submit_button(__('Save Vector Store Settings', 'mxchat'), 'primary', 'submit', true, array('class' => 'mxch-btn mxch-btn-primary')); ?>
1697 1985 </form>
1986 +
1987 + <?php if ($sync_config['enabled']): ?>
1988 + <div class="mxch-field" id="mxchat-vs-import" style="border-top: 1px solid var(--mxch-border, #e2e4e7); padding-top: 20px;"
1989 + data-nonce="<?php echo esc_attr(wp_create_nonce('mxchat_admin_nonce')); ?>">
1990 + <label class="mxch-field-label"><?php esc_html_e('Import Existing Knowledge Base', 'mxchat'); ?></label>
1991 + <p class="mxch-field-description">
1992 + <?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>'); ?>
1993 + </p>
1994 + <div style="display: flex; align-items: center; gap: 8px; margin: 10px 0;">
1995 + <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>
1996 + <button type="button" class="mxch-btn" id="mxchat-vs-import-resume" style="display:none;"><?php esc_html_e('Resume Import', 'mxchat'); ?></button>
1997 + <button type="button" class="mxch-btn" id="mxchat-vs-import-cancel" style="display:none;"><?php esc_html_e('Cancel', 'mxchat'); ?></button>
1998 + </div>
1999 + <div id="mxchat-vs-import-bar" style="display:none; height: 8px; background: var(--mxch-border, #e2e4e7); border-radius: 4px; overflow: hidden; max-width: 420px;">
2000 + <div id="mxchat-vs-import-fill" style="height: 100%; width: 0%; background: #2271b1; transition: width .4s;"></div>
2001 + </div>
2002 + <p class="mxch-field-description" id="mxchat-vs-import-status" style="margin-top: 8px;"></p>
2003 + </div>
2004 +
2005 + <script>
2006 + (function() {
2007 + var wrap = document.getElementById('mxchat-vs-import');
2008 + if (!wrap) { return; }
2009 + var nonce = wrap.getAttribute('data-nonce');
2010 + var startBtn = document.getElementById('mxchat-vs-import-start');
2011 + var resumeBtn = document.getElementById('mxchat-vs-import-resume');
2012 + var cancelBtn = document.getElementById('mxchat-vs-import-cancel');
2013 + var bar = document.getElementById('mxchat-vs-import-bar');
2014 + var fill = document.getElementById('mxchat-vs-import-fill');
2015 + var statusEl = document.getElementById('mxchat-vs-import-status');
2016 + var mappedEl = document.getElementById('mxchat-vs-mapped');
2017 + var pollTimer = null;
2018 +
2019 + function post(action, done) {
2020 + var body = 'action=' + encodeURIComponent(action) + '&nonce=' + encodeURIComponent(nonce);
2021 + fetch(ajaxurl, {
2022 + method: 'POST',
2023 + credentials: 'same-origin',
2024 + headers: {'Content-Type': 'application/x-www-form-urlencoded'},
2025 + body: body
2026 + }).then(function(r) { return r.json(); }).then(done).catch(function() {
2027 + statusEl.textContent = '<?php echo esc_js(__('Request failed — check the browser console.', 'mxchat')); ?>';
2028 + });
2029 + }
2030 +
2031 + function render(state, mapped) {
2032 + if (typeof mapped === 'number' && mappedEl) { mappedEl.textContent = mapped.toLocaleString(); }
2033 + var running = state.status === 'running';
2034 + startBtn.style.display = running ? 'none' : '';
2035 + cancelBtn.style.display = running ? '' : 'none';
2036 + resumeBtn.style.display = (running && state.stalled) ? '' : 'none';
2037 + bar.style.display = (running || state.status === 'done') ? '' : 'none';
2038 + var pct = state.total > 0 ? Math.min(100, Math.round(state.processed / state.total * 100)) : 0;
2039 + if (state.status === 'done') { pct = 100; }
2040 + fill.style.width = pct + '%';
2041 +
2042 + var bits = [];
2043 + 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')); ?>'); }
2044 + if (state.status === 'done') { bits.push('<?php echo esc_js(__('Import complete.', 'mxchat')); ?>'); }
2045 + if (state.status === 'cancelled') { bits.push('<?php echo esc_js(__('Import cancelled.', 'mxchat')); ?>'); }
2046 + if (state.status === 'error') { bits.push('<?php echo esc_js(__('Import error:', 'mxchat')); ?> ' + state.last_error); }
2047 + if (state.status !== 'idle') {
2048 + bits.push(state.processed + '/' + state.total
2049 + + ' — ' + state.imported + ' <?php echo esc_js(__('uploaded', 'mxchat')); ?>'
2050 + + ', ' + state.unchanged + ' <?php echo esc_js(__('unchanged', 'mxchat')); ?>'
2051 + + ', ' + state.skipped_restricted + ' <?php echo esc_js(__('skipped (role-restricted)', 'mxchat')); ?>'
2052 + + ', ' + state.failed + ' <?php echo esc_js(__('failed', 'mxchat')); ?>');
2053 + if (state.failed > 0 && state.last_error && state.status !== 'error') {
2054 + bits.push('<?php echo esc_js(__('Last error:', 'mxchat')); ?> ' + state.last_error);
2055 + }
2056 + }
2057 + statusEl.textContent = bits.join(' ');
2058 +
2059 + if (running && !pollTimer) {
2060 + pollTimer = setInterval(function() {
2061 + post('mxchat_vectorstore_import_status', function(res) {
2062 + if (res && res.success) { render(res.data.state, res.data.mapped); }
2063 + });
2064 + }, 3000);
2065 + } else if (!running && pollTimer) {
2066 + clearInterval(pollTimer);
2067 + pollTimer = null;
2068 + }
2069 + }
2070 +
2071 + startBtn.addEventListener('click', function() {
2072 + startBtn.disabled = true;
2073 + statusEl.textContent = '<?php echo esc_js(__('Starting…', 'mxchat')); ?>';
2074 + post('mxchat_vectorstore_import_start', function(res) {
2075 + startBtn.disabled = false;
2076 + if (res && res.success) { render(res.data.state); }
2077 + else { statusEl.textContent = (res && res.data && res.data.message) ? res.data.message : '<?php echo esc_js(__('Could not start the import.', 'mxchat')); ?>'; }
2078 + });
2079 + });
2080 + resumeBtn.addEventListener('click', function() {
2081 + post('mxchat_vectorstore_import_resume', function(res) {
2082 + if (res && res.success) { render(res.data.state); }
2083 + });
2084 + });
2085 + cancelBtn.addEventListener('click', function() {
2086 + post('mxchat_vectorstore_import_cancel', function(res) {
2087 + if (res && res.success) { render(res.data.state); }
2088 + });
2089 + });
2090 +
2091 + // Pick up an import already in flight when the page loads.
2092 + post('mxchat_vectorstore_import_status', function(res) {
2093 + if (res && res.success && res.data.state.status !== 'idle') { render(res.data.state, res.data.mapped); }
2094 + });
2095 + })();
2096 + </script>
2097 + <?php endif; ?>
1698 2098 </div>
1699 2099 </div>
1700 2100 </div>
1701 2101 <?php
@@ -1820,93 +2220,235 @@
1820 2220 <?php
1821 2221 }
1822 2222
1823 2223 /**
1824 - * Render Knowledge Page Navigation Scripts
2224 + * Render the read-only Knowledge Inspector modal (plan-mxchat-20260628-d8cb4b).
2225 + * Shows exactly what was indexed for an entry: the per-chunk stored text + lengths
2226 + * and (for Pinecone) the stored metadata fields, rendered with the Testing tab's
2227 + * own card components so the two surfaces feel like one system. Self-contained
2228 + * markup + JS so it doesn't entangle the edit-modal init.
1825 2229 */
1826 -function mxchat_render_knowledge_page_scripts() {
2230 +function mxchat_render_inspect_entry_modal() {
1827 2231 ?>
2232 + <div id="mxchat-kb-inspect-modal" class="mxchat-kb-modal">
2233 + <div class="mxchat-kb-modal-content mxchat-kb-inspect-modal-content">
2234 + <div class="mxchat-kb-modal-header">
2235 + <h3 id="mxchat-kb-inspect-title"><?php esc_html_e('Indexed Content', 'mxchat'); ?></h3>
2236 + <span class="mxchat-kb-modal-close" id="mxchat-kb-inspect-close">&times;</span>
2237 + </div>
2238 + <div class="mxchat-kb-inspect-body">
2239 + <div class="mxchat-kb-edit-source" id="mxchat-kb-inspect-source"></div>
2240 + <div class="mxch-testing-results" id="mxchat-kb-inspect-results">
2241 + <div class="mxch-testing-no-data"><?php esc_html_e('Loading indexed content…', 'mxchat'); ?></div>
2242 + </div>
2243 + </div>
2244 + <div class="mxchat-kb-edit-footer">
2245 + <div class="mxchat-kb-edit-notice" id="mxchat-kb-inspect-notice"></div>
2246 + <div class="mxchat-kb-edit-actions">
2247 + <button type="button" id="mxchat-kb-inspect-close-btn" class="mxch-btn mxch-btn-primary">
2248 + <?php esc_html_e('Close', 'mxchat'); ?>
2249 + </button>
2250 + </div>
2251 + </div>
2252 + </div>
2253 + </div>
1828 2254 <script>
1829 2255 (function() {
1830 2256 'use strict';
1831 -
1832 - // Wait for DOM
1833 2257 document.addEventListener('DOMContentLoaded', function() {
1834 - initKnowledgeNavigation();
1835 - initMobileMenu();
1836 - initImportOptions();
1837 - initCustomPostTypesToggle();
1838 - // Sitemap detection is now initialized when user clicks the Sitemap Import option
1839 - });
2258 + var modal = document.getElementById('mxchat-kb-inspect-modal');
2259 + if (!modal) return;
2260 + var closeX = document.getElementById('mxchat-kb-inspect-close');
2261 + var closeBtn = document.getElementById('mxchat-kb-inspect-close-btn');
2262 + var sourceEl = document.getElementById('mxchat-kb-inspect-source');
2263 + var resultsEl= document.getElementById('mxchat-kb-inspect-results');
2264 + var titleEl = document.getElementById('mxchat-kb-inspect-title');
2265 + var noticeEl = document.getElementById('mxchat-kb-inspect-notice');
1840 2266
1841 - function initKnowledgeNavigation() {
1842 - const navLinks = document.querySelectorAll('.mxch-nav-link[data-target], .mxch-mobile-nav-link[data-target]');
1843 - const sections = document.querySelectorAll('.mxch-section');
2267 + var I18N = {
2268 + title: <?php echo wp_json_encode( esc_html__('Indexed Content', 'mxchat') ); ?>,
2269 + loading: <?php echo wp_json_encode( esc_html__('Loading indexed content…', 'mxchat') ); ?>,
2270 + manual: <?php echo wp_json_encode( esc_html__('Manual Content', 'mxchat') ); ?>,
2271 + source: <?php echo wp_json_encode( esc_html__('Source', 'mxchat') ); ?>,
2272 + store: <?php echo wp_json_encode( esc_html__('Storage', 'mxchat') ); ?>,
2273 + type: <?php echo wp_json_encode( esc_html__('Content type', 'mxchat') ); ?>,
2274 + chunksLbl:<?php echo wp_json_encode( esc_html__('Chunks', 'mxchat') ); ?>,
2275 + totalLen: <?php echo wp_json_encode( esc_html__('Total indexed length', 'mxchat') ); ?>,
2276 + chunk: <?php echo wp_json_encode( esc_html__('Chunk', 'mxchat') ); ?>,
2277 + indexed: <?php echo wp_json_encode( esc_html__('Indexed', 'mxchat') ); ?>,
2278 + chars: <?php echo wp_json_encode( esc_html__('chars', 'mxchat') ); ?>,
2279 + showText: <?php echo wp_json_encode( esc_html__('Show indexed text', 'mxchat') ); ?>,
2280 + hideText: <?php echo wp_json_encode( esc_html__('Hide indexed text', 'mxchat') ); ?>,
2281 + wpStore: <?php echo wp_json_encode( esc_html__('Local WordPress database', 'mxchat') ); ?>,
2282 + pcStore: <?php echo wp_json_encode( esc_html__('Pinecone', 'mxchat') ); ?>,
2283 + meta: <?php echo wp_json_encode( esc_html__('Vector metadata', 'mxchat') ); ?>,
2284 + loadFail: <?php echo wp_json_encode( esc_html__('Failed to load indexed content.', 'mxchat') ); ?>,
2285 + netErr: <?php echo wp_json_encode( esc_html__('Network error: ', 'mxchat') ); ?>
2286 + };
1844 2287
1845 - function showSection(targetId) {
1846 - // Hide all sections
1847 - sections.forEach(section => section.classList.remove('active'));
1848 - // Show target section
1849 - const target = document.getElementById(targetId);
1850 - if (target) {
1851 - target.classList.add('active');
1852 - }
1853 - // Update nav links
1854 - navLinks.forEach(link => {
1855 - link.classList.toggle('active', link.dataset.target === targetId);
1856 - });
1857 - // Update URL hash
1858 - history.replaceState(null, null, '#' + targetId);
2288 + function esc(str) {
2289 + var d = document.createElement('div');
2290 + d.textContent = (str === null || str === undefined) ? '' : String(str);
2291 + return d.innerHTML;
1859 2292 }
2293 + function fmt(n) { try { return Number(n).toLocaleString(); } catch (e) { return n; } }
1860 2294
1861 - navLinks.forEach(link => {
1862 - link.addEventListener('click', function(e) {
1863 - e.preventDefault();
1864 - const targetId = this.dataset.target;
1865 - showSection(targetId);
1866 - // Close mobile menu if open
1867 - const mobileMenu = document.querySelector('.mxch-mobile-menu');
1868 - const overlay = document.querySelector('.mxch-mobile-overlay');
1869 - if (mobileMenu) mobileMenu.classList.remove('open');
1870 - if (overlay) overlay.classList.remove('open');
1871 - });
2295 + document.addEventListener('click', function(e) {
2296 + var btn = e.target.closest('.mxchat-inspect-entry-btn');
2297 + if (btn) { e.preventDefault(); open(btn); }
1872 2298 });
2299 + if (closeX) closeX.addEventListener('click', close);
2300 + if (closeBtn) closeBtn.addEventListener('click', close);
2301 + // Overlay click closes, but only when the whole gesture happened on the
2302 + // overlay — otherwise selecting indexed text and releasing past the
2303 + // dialog edge dispatches the click on the overlay and closes it.
2304 + var downOnOverlay = false;
2305 + modal.addEventListener('mousedown', function(e) { downOnOverlay = (e.target === modal); });
2306 + modal.addEventListener('click', function(e) {
2307 + var overlayGesture = downOnOverlay;
2308 + downOnOverlay = false;
2309 + if (e.target === modal && overlayGesture) close();
2310 + });
2311 + document.addEventListener('keydown', function(e) {
2312 + if (e.key === 'Escape' && modal.classList.contains('active')) close();
2313 + });
1873 2314
1874 - // Handle initial hash
1875 - const hash = window.location.hash.substring(1);
1876 - if (hash && document.getElementById(hash)) {
1877 - showSection(hash);
2315 + function close() { modal.classList.remove('active'); }
2316 +
2317 + function open(btn) {
2318 + var entry = {
2319 + sourceUrl: btn.getAttribute('data-source-url') || '',
2320 + entryId: btn.getAttribute('data-entry-id') || '',
2321 + dataSource: btn.getAttribute('data-data-source') || 'wordpress',
2322 + botId: btn.getAttribute('data-bot-id') || 'default',
2323 + nonce: btn.getAttribute('data-nonce') || ''
2324 + };
2325 +
2326 + titleEl.textContent = I18N.title;
2327 + noticeEl.textContent = '';
2328 + noticeEl.className = 'mxchat-kb-edit-notice';
2329 + resultsEl.innerHTML = '<div class="mxch-testing-no-data">' + esc(I18N.loading) + '</div>';
2330 +
2331 + if (entry.sourceUrl && entry.sourceUrl.indexOf('mxchat://') !== 0 && entry.sourceUrl.indexOf('_ungrouped_') !== 0) {
2332 + sourceEl.innerHTML = esc(I18N.source) + ': <a href="' + esc(entry.sourceUrl) + '" target="_blank" rel="noopener">' + esc(entry.sourceUrl) + '</a>';
2333 + } else {
2334 + sourceEl.textContent = I18N.manual;
2335 + }
2336 +
2337 + modal.classList.add('active');
2338 +
2339 + var fd = new FormData();
2340 + fd.append('action', 'mxchat_inspect_entry');
2341 + fd.append('nonce', entry.nonce);
2342 + fd.append('source_url', entry.sourceUrl);
2343 + fd.append('entry_id', entry.entryId);
2344 + fd.append('data_source', entry.dataSource);
2345 + fd.append('bot_id', entry.botId);
2346 +
2347 + fetch(ajaxurl, { method: 'POST', body: fd })
2348 + .then(function(r) { return r.json(); })
2349 + .then(function(resp) {
2350 + if (resp && resp.success) {
2351 + render(resp.data);
2352 + } else {
2353 + var msg = (resp && resp.data && resp.data.message) || I18N.loadFail;
2354 + resultsEl.innerHTML = '';
2355 + showNotice(msg, 'error');
2356 + }
2357 + })
2358 + .catch(function(err) {
2359 + resultsEl.innerHTML = '';
2360 + showNotice(I18N.netErr + err.message, 'error');
2361 + });
1878 2362 }
1879 - }
1880 2363
1881 - function initMobileMenu() {
1882 - const menuBtn = document.querySelector('.mxch-mobile-menu-btn');
1883 - const closeBtn = document.querySelector('.mxch-mobile-menu-close');
1884 - const overlay = document.querySelector('.mxch-mobile-overlay');
1885 - const menu = document.querySelector('.mxch-mobile-menu');
2364 + function render(data) {
2365 + var storeLabel = data.store === 'pinecone' ? I18N.pcStore : I18N.wpStore;
2366 + var html = '';
1886 2367
1887 - if (menuBtn && menu) {
1888 - menuBtn.addEventListener('click', function() {
1889 - menu.classList.add('open');
1890 - if (overlay) overlay.classList.add('open');
2368 + // Summary card — what this entry is + how much was indexed.
2369 + html += '<div class="match-card above-threshold">' +
2370 + '<div class="match-header">' +
2371 + '<div class="match-title"><span class="status-icon">&#128230;</span> ' + esc(data.chunk_count) + ' ' + esc(I18N.chunksLbl.toLowerCase()) + '</div>' +
2372 + '<span class="context-label">' + esc(storeLabel) + '</span>' +
2373 + '</div>' +
2374 + '<div class="mxch-testing-field"><label>' + esc(I18N.type) + '</label><code>' + esc(data.content_type || '—') + '</code> ' +
2375 + '&nbsp; <label style="display:inline; text-transform:none; letter-spacing:0; font-weight:600;">' + esc(I18N.totalLen) + ':</label> ' + esc(fmt(data.assembled_length)) + ' ' + esc(I18N.chars) + '</div>';
2376 + if (data.metadata_note) {
2377 + html += '<div class="match-source"><span class="source-icon">&#8505;&#65039;</span> ' + esc(data.metadata_note) + '</div>';
2378 + }
2379 + html += '</div>';
2380 +
2381 + // One card per stored chunk — the actual embedded text.
2382 + var chunks = data.chunks || [];
2383 + chunks.forEach(function(chunk, i) {
2384 + var num = (chunk.index !== null && chunk.index !== undefined) ? (chunk.index + 1) : (i + 1);
2385 + var metaRows = '';
2386 + if (chunk.metadata && typeof chunk.metadata === 'object') {
2387 + var keys = Object.keys(chunk.metadata);
2388 + if (keys.length) {
2389 + metaRows += '<div class="chunk-detail-row chunk-used" style="display:block;"><span class="chunk-detail-num">' + esc(I18N.meta) + '</span></div>';
2390 + keys.forEach(function(k) {
2391 + metaRows += '<div class="chunk-detail-row"><span class="chunk-detail-num">' + esc(k) + '</span><span class="chunk-detail-score">' + esc(chunk.metadata[k]) + '</span></div>';
2392 + });
2393 + }
2394 + }
2395 + html += '<div class="match-card above-threshold">' +
2396 + '<div class="match-header">' +
2397 + '<div class="match-title"><span class="status-icon">&#10003;</span> ' + esc(I18N.chunk) + ' ' + esc(num) +
2398 + '<span class="chunk-summary">' + esc(fmt(chunk.length)) + ' ' + esc(I18N.chars) + '</span>' +
2399 + '</div>' +
2400 + '<span class="context-label">' + esc(I18N.indexed) + '</span>' +
2401 + '</div>' +
2402 + '<span class="chunk-expand-toggle" data-chunk="' + i + '">&#9654; ' + esc(I18N.showText) + '</span>' +
2403 + '<div class="chunk-details" data-chunk="' + i + '">' +
2404 + '<pre class="mxch-kb-inspect-chunk-text">' + esc(chunk.text) + '</pre>' +
2405 + metaRows +
2406 + '</div>' +
2407 + '</div>';
1891 2408 });
1892 - }
1893 2409
1894 - if (closeBtn && menu) {
1895 - closeBtn.addEventListener('click', function() {
1896 - menu.classList.remove('open');
1897 - if (overlay) overlay.classList.remove('open');
2410 + resultsEl.innerHTML = html;
2411 +
2412 + resultsEl.querySelectorAll('.chunk-expand-toggle').forEach(function(toggle) {
2413 + toggle.addEventListener('click', function() {
2414 + var id = this.getAttribute('data-chunk');
2415 + var details = resultsEl.querySelector('.chunk-details[data-chunk="' + id + '"]');
2416 + if (!details) return;
2417 + var expanded = details.classList.toggle('expanded');
2418 + this.innerHTML = (expanded ? '&#9660; ' + esc(I18N.hideText) : '&#9654; ' + esc(I18N.showText));
2419 + });
1898 2420 });
1899 2421 }
1900 2422
1901 - if (overlay && menu) {
1902 - overlay.addEventListener('click', function() {
1903 - menu.classList.remove('open');
1904 - overlay.classList.remove('open');
1905 - });
2423 + function showNotice(msg, type) {
2424 + noticeEl.textContent = msg;
2425 + noticeEl.className = 'mxchat-kb-edit-notice' + (type ? ' ' + type : '');
1906 2426 }
1907 - }
2427 + });
2428 + })();
2429 + </script>
2430 + <?php
2431 +}
1908 2432
2433 +/**
2434 + * Render Knowledge Page Navigation Scripts
2435 + */
2436 +function mxchat_render_knowledge_page_scripts() {
2437 + ?>
2438 + <script>
2439 + (function() {
2440 + 'use strict';
2441 +
2442 + // Wait for DOM
2443 + document.addEventListener('DOMContentLoaded', function() {
2444 + // Tab navigation + mobile menu live in the shared shell script
2445 + // (js/admin-sidebar.js), enqueued for this page by plan c192a4.
2446 + initImportOptions();
2447 + initCustomPostTypesToggle();
2448 + // Sitemap detection is now initialized when user clicks the Sitemap Import option
2449 + });
2450 +
1909 2451 function initImportOptions() {
1910 2452 const importBoxes = document.querySelectorAll('.mxchat-import-box');
1911 2453 const urlInputArea = document.getElementById('mxchat-url-input-area');
1912 2454 const contentInputArea = document.getElementById('mxchat-content-input-area');
@@ -2017,9 +2559,14 @@
2017 2559
2018 2560 if (!modal) return;
2019 2561
2020 2562 var currentEntry = {};
2563 + var loadedContent = '';
2021 2564
2565 + var EDIT_I18N = {
2566 + discard: <?php echo wp_json_encode( __('Discard your unsaved changes to this entry?', 'mxchat') ); ?>
2567 + };
2568 +
2022 2569 // Bind edit buttons (delegated)
2023 2570 document.addEventListener('click', function(e) {
2024 2571 var btn = e.target.closest('.mxchat-edit-entry-btn');
2025 2572 if (btn) {
@@ -2027,13 +2574,16 @@
2027 2574 openEditModal(btn);
2028 2575 }
2029 2576 });
2030 2577
2031 - // Close handlers
2032 - if (closeBtn) closeBtn.addEventListener('click', closeModal);
2033 - if (cancelBtn) cancelBtn.addEventListener('click', closeModal);
2034 - modal.addEventListener('click', function(e) {
2035 - if (e.target === modal) closeModal();
2578 + // Close handlers. The overlay deliberately has no click-to-close: a click
2579 + // fires on the common ancestor of its mousedown and mouseup, so releasing
2580 + // a text-selection drag past the dialog edge targets the overlay and would
2581 + // discard the edit. Closing is explicit only, and confirms when dirty.
2582 + if (closeBtn) closeBtn.addEventListener('click', requestClose);
2583 + if (cancelBtn) cancelBtn.addEventListener('click', requestClose);
2584 + document.addEventListener('keydown', function(e) {
2585 + if (e.key === 'Escape' && modal.classList.contains('active')) requestClose();
2036 2586 });
2037 2587
2038 2588 // Character count
2039 2589 if (textarea) {
@@ -2055,8 +2605,9 @@
2055 2605 };
2056 2606
2057 2607 // Reset state
2058 2608 textarea.value = '';
2609 + loadedContent = '';
2059 2610 textarea.placeholder = 'Loading content...';
2060 2611 textarea.disabled = true;
2061 2612 saveBtn.disabled = true;
2062 2613 notice.textContent = '';
@@ -2087,8 +2638,9 @@
2087 2638 .then(function(r) { return r.json(); })
2088 2639 .then(function(resp) {
2089 2640 if (resp.success) {
2090 2641 textarea.value = resp.data.content || '';
2642 + loadedContent = textarea.value;
2091 2643 textarea.disabled = false;
2092 2644 textarea.placeholder = 'Edit your content here...';
2093 2645 saveBtn.disabled = false;
2094 2646 currentEntry.contentType = resp.data.content_type || 'content';
@@ -2143,13 +2695,23 @@
2143 2695 if (saveSpin) saveSpin.style.display = 'none';
2144 2696 saveBtn.disabled = false;
2145 2697
2146 2698 if (resp.success) {
2147 - showNotice('Saved successfully!', 'success');
2148 - setTimeout(function() {
2149 - closeModal();
2150 - window.location.reload();
2151 - }, 1000);
2699 + if (currentEntry.dataSource === 'pinecone') {
2700 + // Pinecone list reads are eventually consistent — the reloaded
2701 + // table may show the old text for up to ~60 seconds.
2702 + showNotice('Saved! Pinecone changes may take up to 60 seconds to appear — use "Refresh Entries" if the list still shows the old text.', 'success');
2703 + setTimeout(function() {
2704 + closeModal();
2705 + window.location.reload();
2706 + }, 2500);
2707 + } else {
2708 + showNotice('Saved successfully!', 'success');
2709 + setTimeout(function() {
2710 + closeModal();
2711 + window.location.reload();
2712 + }, 1000);
2713 + }
2152 2714 } else {
2153 2715 showNotice((resp.data && resp.data.message) || 'Save failed.', 'error');
2154 2716 }
2155 2717 })
@@ -2158,8 +2720,17 @@
2158 2720 if (saveSpin) saveSpin.style.display = 'none';
2159 2721 saveBtn.disabled = false;
2160 2722 showNotice('Network error: ' + err.message, 'error');
2161 2723 });
2724 + }
2725 +
2726 + function isDirty() {
2727 + return !textarea.disabled && textarea.value !== loadedContent;
2728 + }
2729 +
2730 + function requestClose() {
2731 + if (isDirty() && !window.confirm(EDIT_I18N.discard)) return;
2732 + closeModal();
2162 2733 }
2163 2734
2164 2735 function closeModal() {
2165 2736 modal.classList.remove('active');