| @@ -47,83 +47,10 @@ | ||
| 47 | 47 | add_action('wp_ajax_mxchat_get_debug_log', array($this, 'mxchat_get_debug_log_callback')); |
| 48 | 48 | add_action('wp_ajax_mxchat_clear_debug_log', array($this, 'mxchat_clear_debug_log_callback')); |
| 49 | 49 | add_action('wp_ajax_mxchat_export_settings', array($this, 'mxchat_export_settings_callback')); |
| 50 | 50 | add_action('wp_ajax_mxchat_reset_all_settings', array($this, 'mxchat_reset_all_settings_callback')); |
| 51 | - | |
| 52 | - // Custom (OpenAI-compatible) Provider connection test | |
| 53 | - add_action('wp_ajax_mxchat_test_custom_provider', array($this, 'mxchat_test_custom_provider_callback')); | |
| 54 | 51 | } |
| 55 | 52 | |
| 56 | -/** | |
| 57 | - * Test connection to a Custom (OpenAI-compatible) provider by hitting its /models endpoint | |
| 58 | - * with whichever auth scheme the user configured. Reports model count or a clean error. | |
| 59 | - */ | |
| 60 | -public function mxchat_test_custom_provider_callback() { | |
| 61 | - check_ajax_referer('mxchat_test_custom_provider'); | |
| 62 | - if (!current_user_can('manage_options')) { | |
| 63 | - wp_send_json_error(array('message' => esc_html__('Unauthorized', 'mxchat'))); | |
| 64 | - } | |
| 65 | - | |
| 66 | - $options = get_option('mxchat_options', array()); | |
| 67 | - $base_url = isset($options['custom_provider_base_url']) ? trim((string) $options['custom_provider_base_url']) : ''; | |
| 68 | - $api_key = isset($options['custom_provider_api_key']) ? trim((string) $options['custom_provider_api_key']) : ''; | |
| 69 | - $auth = isset($options['custom_provider_auth_scheme']) ? $options['custom_provider_auth_scheme'] : 'bearer'; | |
| 70 | - $api_version = isset($options['custom_provider_api_version']) ? trim((string) $options['custom_provider_api_version']) : ''; | |
| 71 | - | |
| 72 | - if (empty($base_url)) { | |
| 73 | - wp_send_json_error(array('message' => esc_html__('Base URL is empty. Save it first.', 'mxchat'))); | |
| 74 | - } | |
| 75 | - | |
| 76 | - $url = rtrim($base_url, '/') . '/models'; | |
| 77 | - if (!empty($api_version)) { | |
| 78 | - $url = add_query_arg('api-version', $api_version, $url); | |
| 79 | - } | |
| 80 | - | |
| 81 | - $headers = array('Content-Type' => 'application/json'); | |
| 82 | - if (!empty($api_key)) { | |
| 83 | - if ($auth === 'api-key') { | |
| 84 | - $headers['api-key'] = $api_key; | |
| 85 | - } else { | |
| 86 | - $headers['Authorization'] = 'Bearer ' . $api_key; | |
| 87 | - } | |
| 88 | - } | |
| 89 | - | |
| 90 | - $response = wp_remote_get($url, array( | |
| 91 | - 'headers' => $headers, | |
| 92 | - 'timeout' => 10, | |
| 93 | - )); | |
| 94 | - | |
| 95 | - if (is_wp_error($response)) { | |
| 96 | - wp_send_json_error(array('message' => sprintf(esc_html__('Network error: %s', 'mxchat'), esc_html($response->get_error_message())))); | |
| 97 | - } | |
| 98 | - | |
| 99 | - $code = (int) wp_remote_retrieve_response_code($response); | |
| 100 | - if ($code === 401 || $code === 403) { | |
| 101 | - wp_send_json_error(array('message' => sprintf(esc_html__('Auth rejected (HTTP %d). Check API key and auth scheme.', 'mxchat'), $code))); | |
| 102 | - } | |
| 103 | - if ($code === 404) { | |
| 104 | - wp_send_json_error(array('message' => esc_html__('Endpoint not found (HTTP 404). Check the Base URL.', 'mxchat'))); | |
| 105 | - } | |
| 106 | - if ($code < 200 || $code >= 300) { | |
| 107 | - wp_send_json_error(array('message' => sprintf(esc_html__('Upstream returned HTTP %d.', 'mxchat'), $code))); | |
| 108 | - } | |
| 109 | - | |
| 110 | - $body = json_decode(wp_remote_retrieve_body($response), true); | |
| 111 | - $count = 0; | |
| 112 | - if (is_array($body)) { | |
| 113 | - if (isset($body['data']) && is_array($body['data'])) { | |
| 114 | - $count = count($body['data']); | |
| 115 | - } elseif (isset($body['models']) && is_array($body['models'])) { | |
| 116 | - $count = count($body['models']); | |
| 117 | - } | |
| 118 | - } | |
| 119 | - | |
| 120 | - wp_send_json_success(array( | |
| 121 | - 'message' => sprintf(esc_html__('Connection OK — %d model(s) reported.', 'mxchat'), $count), | |
| 122 | - 'count' => $count, | |
| 123 | - )); | |
| 124 | -} | |
| 125 | - | |
| 126 | 53 | // ======================================== |
| 127 | 54 | // SETTINGS AJAX HANDLERS |
| 128 | 55 | // ======================================== |
| 129 | 56 | |
| @@ -174,15 +101,19 @@ | ||
| 174 | 101 | //error_log('MXChat Save: Setting model to openrouter'); |
| 175 | 102 | $options['model'] = 'openrouter'; |
| 176 | 103 | } else { |
| 177 | 104 | //error_log('MXChat Save: Checking against whitelist'); |
| 178 | - // Catalog refactor (plan-d14e89): canonical allowlist lives in | |
| 179 | - // includes/class-mxchat-model-catalog.php. A new chat model | |
| 180 | - // added there is automatically accepted by autosave. | |
| 181 | - if (!class_exists('MxChat_Model_Catalog')) { | |
| 182 | - require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-mxchat-model-catalog.php'; | |
| 183 | - } | |
| 184 | - $allowed_models = MxChat_Model_Catalog::chat_model_ids(); | |
| 105 | + $allowed_models = array( | |
| 106 | + 'gemini-3-pro-preview', 'gemini-3-flash-preview', 'gemini-2.5-pro', 'gemini-2.5-flash', 'gemini-2.5-flash-lite', | |
| 107 | + 'gemini-2.0-flash', 'gemini-2.0-flash-lite', 'gemini-1.5-pro', 'gemini-1.5-flash', | |
| 108 | + 'grok-4-0709', 'grok-4-1-fast-reasoning', 'grok-4-1-fast-non-reasoning', 'grok-3-beta', 'grok-3-fast-beta', 'grok-3-mini-beta', | |
| 109 | + 'grok-3-mini-fast-beta', 'grok-2', | |
| 110 | + 'deepseek-chat', | |
| 111 | + 'claude-opus-4-6', 'claude-opus-4-5', 'claude-sonnet-4-6', | |
| 112 | + 'claude-sonnet-4-5-20250929', 'claude-opus-4-1-20250805', 'claude-haiku-4-5-20251001', | |
| 113 | + 'claude-opus-4-20250514', 'claude-sonnet-4-20250514', | |
| 114 | + 'gpt-5.2', 'gpt-5.1-chat-latest', 'gpt-5.1-2025-11-13', 'gpt-5', 'gpt-5-mini', 'gpt-5-nano', | |
| 115 | + ); | |
| 185 | 116 | |
| 186 | 117 | //error_log('MXChat Save: in_array result: ' . (in_array($value, $allowed_models) ? 'YES' : 'NO')); |
| 187 | 118 | |
| 188 | 119 | if (in_array($value, $allowed_models)) { |
| @@ -258,15 +189,8 @@ | ||
| 258 | 189 | if ($rag_limit < 3) $rag_limit = 3; |
| 259 | 190 | if ($rag_limit > 10) $rag_limit = 10; |
| 260 | 191 | $options[$field_name] = $rag_limit; |
| 261 | 192 | break; |
| 262 | - case 'rag_chunks_limit': | |
| 263 | - // Validate and save - enforce min 8, max 20, default 15 | |
| 264 | - $chunks_limit = intval($value); | |
| 265 | - if ($chunks_limit < 8) $chunks_limit = 8; | |
| 266 | - if ($chunks_limit > 20) $chunks_limit = 20; | |
| 267 | - $options[$field_name] = $chunks_limit; | |
| 268 | - break; | |
| 269 | 193 | case 'live_agent_status': |
| 270 | 194 | //error_log('MXChat Save: Processing live_agent_status'); |
| 271 | 195 | // Set the new value |
| 272 | 196 | $options[$field_name] = ($value === 'on') ? 'on' : 'off'; |
| @@ -299,12 +223,8 @@ | ||
| 299 | 223 | // Validate script loading strategy value |
| 300 | 224 | $allowed_strategies = array('default', 'defer', 'delay_1s', 'delay_3s', 'delay_5s', 'on_interaction'); |
| 301 | 225 | $options[$field_name] = in_array($value, $allowed_strategies) ? $value : 'default'; |
| 302 | 226 | break; |
| 303 | - case 'auto_retry_on_transient_error': | |
| 304 | - // Boolean toggle — accept 1/0/on/off, default to '1' if any truthy value. | |
| 305 | - $options[$field_name] = ($value === '1' || $value === 'on' || $value === 1 || $value === true) ? '1' : '0'; | |
| 306 | - break; | |
| 307 | 227 | default: |
| 308 | 228 | // Handle transcripts options |
| 309 | 229 | if (strpos($name, 'mxchat_transcripts_options') !== false) { |
| 310 | 230 | // Extract field name from mxchat_transcripts_options[field_name] |
| @@ -443,10 +363,9 @@ | ||
| 443 | 363 | 'contextual_awareness_toggle', |
| 444 | 364 | 'citation_links_toggle', |
| 445 | 365 | 'enable_email_block', |
| 446 | 366 | 'enable_name_field', |
| 447 | - 'custom_provider_for_embeddings', | |
| 448 | - 'custom_provider_for_images' | |
| 367 | + 'show_frontend_debugger' | |
| 449 | 368 | ])) { |
| 450 | 369 | //error_log('MXChat Save: Processing toggle: ' . $field_name); |
| 451 | 370 | $options[$field_name] = ($value === 'on') ? 'on' : 'off'; |
| 452 | 371 | } else { |