| @@ -283,27 +283,8 @@ | ||
| 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 | -/** | |
| 306 | 287 | * Render Multi-Bot Selector |
| 307 | 288 | */ |
| 308 | 289 | function mxchat_render_knowledge_bot_selector($multibot_active, $current_bot_id) { |
| 309 | 290 | if (!$multibot_active || !class_exists('MxChat_Multi_Bot_Manager')) { |
| @@ -326,15 +307,9 @@ | ||
| 326 | 307 | </option> |
| 327 | 308 | <?php endforeach; ?> |
| 328 | 309 | </select> |
| 329 | 310 | <span style="color: var(--mxch-text-secondary); font-size: 13px;"> |
| 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 | - ?> | |
| 311 | + <?php esc_html_e('Content will be added to the selected bot\'s knowledge base', 'mxchat'); ?> | |
| 337 | 312 | </span> |
| 338 | 313 | <span id="mxchat-bot-save-status" style="display: none; color: var(--mxch-success); font-size: 13px;"> |
| 339 | 314 | ✓ <?php esc_html_e('Saved', 'mxchat'); ?> |
| 340 | 315 | </span> |
| @@ -464,20 +439,8 @@ | ||
| 464 | 439 | $required_key_type = 'Voyage AI'; |
| 465 | 440 | } elseif (strpos($embedding_model, 'gemini-embedding-') !== false) { |
| 466 | 441 | $required_key_type = 'Google Gemini'; |
| 467 | 442 | } |
| 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 | - } | |
| 480 | 443 | ?> |
| 481 | 444 | <div id="import-options" class="mxch-section active"> |
| 482 | 445 | <div class="mxch-content-header"> |
| 483 | 446 | <h1 class="mxch-content-title"><?php esc_html_e('Import Options', 'mxchat'); ?></h1> |
| @@ -493,18 +456,9 @@ | ||
| 493 | 456 | <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"/> |
| 494 | 457 | <?php endif; ?> |
| 495 | 458 | </svg> |
| 496 | 459 | <div> |
| 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): ?> | |
| 460 | + <?php if ($has_required_key): ?> | |
| 507 | 461 | <?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)); ?> |
| 508 | 462 | <?php else: ?> |
| 509 | 463 | <strong><?php esc_html_e('Important:', 'mxchat'); ?></strong> |
| 510 | 464 | <?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); ?> |
| @@ -721,14 +675,8 @@ | ||
| 721 | 675 | </div> |
| 722 | 676 | <p class="mxch-field-description"> |
| 723 | 677 | <?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'); ?> |
| 724 | 678 | </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> | |
| 731 | 679 | <button type="submit" name="submit_pdf_file" class="mxch-btn mxch-btn-primary"> |
| 732 | 680 | <?php esc_html_e('Import PDF', 'mxchat'); ?> |
| 733 | 681 | </button> |
| 734 | 682 | </form> |
| @@ -745,14 +693,8 @@ | ||
| 745 | 693 | </div> |
| 746 | 694 | <p class="mxch-field-description"> |
| 747 | 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'); ?> |
| 748 | 696 | </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 | 697 | <button type="submit" name="submit_document_file" class="mxch-btn mxch-btn-primary"> |
| 756 | 698 | <?php esc_html_e('Import Document', 'mxchat'); ?> |
| 757 | 699 | </button> |
| 758 | 700 | </form> |
| @@ -1127,9 +1069,16 @@ | ||
| 1127 | 1069 | </span> |
| 1128 | 1070 | </div> |
| 1129 | 1071 | </td> |
| 1130 | 1072 | <td class="mxchat-url-cell" style="padding: 12px 16px; font-size: 13px;"> |
| 1131 | - <?php echo MxChat_Knowledge_Manager::mxchat_source_cell_html($source_url, $current_bot_id, true); ?> | |
| 1073 | + <?php if (!empty($source_url) && strpos($source_url, 'mxchat://') !== 0 && strpos($source_url, '_ungrouped_') !== 0) : ?> | |
| 1074 | + <a href="<?php echo esc_url($source_url); ?>" target="_blank" style="color: var(--mxch-primary); text-decoration: none;"> | |
| 1075 | + <span class="dashicons dashicons-external" style="font-size: 14px;"></span> | |
| 1076 | + <?php esc_html_e('View Source', 'mxchat'); ?> | |
| 1077 | + </a> | |
| 1078 | + <?php else : ?> | |
| 1079 | + <span style="color: var(--mxch-text-muted);"><?php esc_html_e('Manual Content', 'mxchat'); ?></span> | |
| 1080 | + <?php endif; ?> | |
| 1132 | 1081 | </td> |
| 1133 | 1082 | <td class="mxchat-actions-cell" style="padding: 12px 16px; white-space: nowrap;"> |
| 1134 | 1083 | <button type="button" |
| 1135 | 1084 | class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-inspect-entry-btn" |
| @@ -1278,10 +1227,16 @@ | ||
| 1278 | 1227 | $actual_source = $source_url; |
| 1279 | 1228 | if (strpos($source_url, '_ungrouped_') === 0) { |
| 1280 | 1229 | $actual_source = $prompt->source_url ?? ''; |
| 1281 | 1230 | } |
| 1282 | - echo MxChat_Knowledge_Manager::mxchat_source_cell_html($actual_source, $current_bot_id, false); | |
| 1283 | - ?> | |
| 1231 | + if (!empty($actual_source) && strpos($actual_source, 'mxchat://') !== 0) : ?> | |
| 1232 | + <a href="<?php echo esc_url($actual_source); ?>" target="_blank" style="color: var(--mxch-primary); text-decoration: none;"> | |
| 1233 | + <span class="dashicons dashicons-external" style="font-size: 14px;"></span> | |
| 1234 | + <?php esc_html_e('View', 'mxchat'); ?> | |
| 1235 | + </a> | |
| 1236 | + <?php else : ?> | |
| 1237 | + <span style="color: var(--mxch-text-muted);"><?php esc_html_e('Manual', 'mxchat'); ?></span> | |
| 1238 | + <?php endif; ?> | |
| 1284 | 1239 | </td> |
| 1285 | 1240 | <td style="padding: 12px 16px; white-space: nowrap;"> |
| 1286 | 1241 | <button type="button" |
| 1287 | 1242 | class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-inspect-entry-btn" |
| @@ -1374,97 +1329,13 @@ | ||
| 1374 | 1329 | <?php endif; ?> |
| 1375 | 1330 | </div> |
| 1376 | 1331 | </div> |
| 1377 | 1332 | </div> |
| 1378 | - | |
| 1379 | - <?php mxchat_render_kb_reimport_card(!empty($current_bot_id) ? $current_bot_id : 'default'); ?> | |
| 1380 | 1333 | </div> |
| 1381 | 1334 | <?php |
| 1382 | 1335 | } |
| 1383 | 1336 | |
| 1384 | 1337 | /** |
| 1385 | - * "Re-import affected entries" card (plan 89739b). | |
| 1386 | - * | |
| 1387 | - * The owner-facing side of wp mxchat kb-reimport: check first (no embedding | |
| 1388 | - * request, nothing written), read the list, then confirm. Both halves run in | |
| 1389 | - * resumable steps through the mxchat_kb_reimport AJAX action; the script is | |
| 1390 | - * js/knowledge-reimport.js. Everything dynamic is drawn there; this is the | |
| 1391 | - * resting markup. | |
| 1392 | - */ | |
| 1393 | -function mxchat_render_kb_reimport_card($current_bot_id = 'default') { | |
| 1394 | - if (!class_exists('MxChat_Knowledge_Manager')) { | |
| 1395 | - return; | |
| 1396 | - } | |
| 1397 | - ?> | |
| 1398 | - <div class="mxch-card mxch-kb-reimport" id="mxchat-kb-reimport" | |
| 1399 | - data-nonce="<?php echo esc_attr(wp_create_nonce('mxchat_kb_reimport')); ?>" | |
| 1400 | - data-bot="<?php echo esc_attr($current_bot_id); ?>"> | |
| 1401 | - <div class="mxch-card-header"> | |
| 1402 | - <h3 class="mxch-card-title"> | |
| 1403 | - <svg class="mxch-card-title-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><polyline points="1 20 1 14 7 14"/><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"/></svg> | |
| 1404 | - <?php esc_html_e('Re-import affected entries', 'mxchat'); ?> | |
| 1405 | - </h3> | |
| 1406 | - </div> | |
| 1407 | - <div class="mxch-card-body"> | |
| 1408 | - <p class="mxch-field-description"><?php esc_html_e('Earlier versions stored some imported text incorrectly: currency signs and accents were dropped, HTML character codes were left in, and right-to-left PDF text was saved backwards. This finds the entries that still hold that text and rebuilds them from their source. Checking changes nothing.', 'mxchat'); ?></p> | |
| 1409 | - | |
| 1410 | - <div class="mxch-kb-reimport-controls"> | |
| 1411 | - <div class="mxch-field"> | |
| 1412 | - <label class="mxch-field-label" for="mxchat-kb-reimport-before"><?php esc_html_e('Entries last written before', 'mxchat'); ?></label> | |
| 1413 | - <input type="date" id="mxchat-kb-reimport-before" class="mxch-input mxch-input-sm" value="<?php echo esc_attr(MxChat_Knowledge_Manager::REIMPORT_DEFAULT_BEFORE); ?>" max="<?php echo esc_attr(gmdate('Y-m-d', time() + DAY_IN_SECONDS)); ?>" /> | |
| 1414 | - </div> | |
| 1415 | - <button type="button" class="mxch-btn mxch-btn-secondary" id="mxchat-kb-reimport-check"><?php esc_html_e('Check knowledge base', 'mxchat'); ?></button> | |
| 1416 | - </div> | |
| 1417 | - <p class="mxch-field-hint"><?php esc_html_e('The date is the release that carried the last of these fixes. Choose a later one if this site was updated after that.', 'mxchat'); ?></p> | |
| 1418 | - | |
| 1419 | - <!-- Also offer entries whose page was edited after they were imported (plan a00ef8); off by default --> | |
| 1420 | - <div class="mxch-field mxch-kb-reimport-edited"> | |
| 1421 | - <label class="toggle-switch"> | |
| 1422 | - <input type="checkbox" id="mxchat-kb-reimport-edited" name="mxchat_kb_reimport_edited" value="1" /> | |
| 1423 | - <span class="slider"></span> | |
| 1424 | - </label> | |
| 1425 | - <div class="mxch-kb-reimport-edited-text"> | |
| 1426 | - <label class="mxch-field-label" for="mxchat-kb-reimport-edited"><?php esc_html_e('Also rewrite entries whose page was edited after they were imported', 'mxchat'); ?></label> | |
| 1427 | - <p class="mxch-field-description"><?php esc_html_e('An entry older than its post, page, product or media file is rebuilt from it as it reads today. A site with auto-sync on does not need this.', 'mxchat'); ?></p> | |
| 1428 | - </div> | |
| 1429 | - </div> | |
| 1430 | - | |
| 1431 | - <div class="mxch-kb-reimport-progress" hidden> | |
| 1432 | - <div class="mxch-progress-bar" hidden><div class="mxch-progress-bar-fill"></div></div> | |
| 1433 | - <p class="mxch-progress-label" aria-live="polite"></p> | |
| 1434 | - </div> | |
| 1435 | - | |
| 1436 | - <div class="mxch-notice mxch-notice-error mxch-kb-reimport-error" role="alert" hidden> | |
| 1437 | - <svg class="mxch-notice-icon" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg> | |
| 1438 | - <span></span> | |
| 1439 | - </div> | |
| 1440 | - | |
| 1441 | - <div class="mxch-kb-reimport-results" hidden> | |
| 1442 | - <div class="mxch-notice mxch-notice-success mxch-kb-reimport-done" hidden> | |
| 1443 | - <svg class="mxch-notice-icon" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg> | |
| 1444 | - <span></span> | |
| 1445 | - </div> | |
| 1446 | - <div class="mxch-kb-reimport-counts"></div> | |
| 1447 | - <ul class="mxch-kb-reimport-list mxch-kb-reimport-entries" hidden></ul> | |
| 1448 | - <p class="mxch-field-hint mxch-kb-reimport-more" hidden></p> | |
| 1449 | - <details class="mxch-disclosure mxch-kb-reimport-others" hidden> | |
| 1450 | - <summary class="mxch-disclosure-summary"><span class="mxch-disclosure-summary-text"></span><span class="mxch-disclosure-summary-hint"><?php esc_html_e('Never changed or removed by this tool', 'mxchat'); ?></span></summary> | |
| 1451 | - <div class="mxch-disclosure-body"> | |
| 1452 | - <ul class="mxch-kb-reimport-list mxch-kb-reimport-notes"></ul> | |
| 1453 | - </div> | |
| 1454 | - </details> | |
| 1455 | - </div> | |
| 1456 | - </div> | |
| 1457 | - <div class="mxch-card-footer mxch-kb-reimport-footer" hidden> | |
| 1458 | - <button type="button" class="mxch-btn mxch-btn-primary" id="mxchat-kb-reimport-apply"></button> | |
| 1459 | - <button type="button" class="mxch-btn mxch-btn-ghost" id="mxchat-kb-reimport-clear"><?php esc_html_e('Clear', 'mxchat'); ?></button> | |
| 1460 | - <span class="mxch-field-hint mxch-kb-reimport-cost"><?php esc_html_e('Each rewritten entry is embedded again with your embedding provider.', 'mxchat'); ?></span> | |
| 1461 | - </div> | |
| 1462 | - </div> | |
| 1463 | - <?php | |
| 1464 | -} | |
| 1465 | - | |
| 1466 | -/** | |
| 1467 | 1338 | * Render Auto-Sync Section |
| 1468 | 1339 | */ |
| 1469 | 1340 | function mxchat_render_auto_sync_section($knowledge_manager) { |
| 1470 | 1341 | ?> |
| @@ -2017,12 +1888,8 @@ | ||
| 2017 | 1888 | </div> |
| 2018 | 1889 | <script type="application/json" id="mxchat-pinecone-docs-state"><?php echo wp_json_encode(array( |
| 2019 | 1890 | 'verified_host' => $pc_verified, |
| 2020 | 1891 | 'expected_dimension' => (int) $pc_expected_dim, |
| 2021 | - // 47c61f: the status notice's two texts, so the page can | |
| 2022 | - // keep it in step with the host typed in the field. | |
| 2023 | - 'status_checked' => __('Document index checked: %1$s (%2$d dimensions).', 'mxchat'), | |
| 2024 | - 'status_unchecked' => __('Not checked yet. Create a document index below, or enter its host above and click Check index. The index type only saves once the host has been checked.', 'mxchat'), | |
| 2025 | 1892 | 'migration' => $pc_migration, |
| 2026 | 1893 | // 3e83e4: what the LIVE chatbot is on right now, so the |
| 2027 | 1894 | // page can tell a copy-in-progress from a switch. |
| 2028 | 1895 | 'index_type' => $pc_index_type, |