| @@ -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,10 +101,8 @@ | ||
| 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 | - // Keep in sync with the Settings-API sanitize allow-list in | |
| 179 | - // includes/class-mxchat-admin.php (mxchat_options_validate). | |
| 180 | 105 | $allowed_models = array( |
| 181 | 106 | 'gemini-3-pro-preview', 'gemini-3-flash-preview', 'gemini-2.5-pro', 'gemini-2.5-flash', 'gemini-2.5-flash-lite', |
| 182 | 107 | 'gemini-2.0-flash', 'gemini-2.0-flash-lite', 'gemini-1.5-pro', 'gemini-1.5-flash', |
| 183 | 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', |
| @@ -182,14 +107,13 @@ | ||
| 182 | 107 | 'gemini-2.0-flash', 'gemini-2.0-flash-lite', 'gemini-1.5-pro', 'gemini-1.5-flash', |
| 183 | 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', |
| 184 | 109 | 'grok-3-mini-fast-beta', 'grok-2', |
| 185 | 110 | 'deepseek-chat', |
| 186 | - 'claude-opus-4-7', 'claude-opus-4-6', 'claude-opus-4-5', 'claude-sonnet-4-6', | |
| 111 | + 'claude-opus-4-6', 'claude-opus-4-5', 'claude-sonnet-4-6', | |
| 187 | 112 | 'claude-sonnet-4-5-20250929', 'claude-opus-4-1-20250805', 'claude-haiku-4-5-20251001', |
| 188 | 113 | 'claude-opus-4-20250514', 'claude-sonnet-4-20250514', |
| 189 | - 'gpt-5.5', 'gpt-5.4', 'gpt-5.4-mini', 'gpt-5.4-nano', 'gpt-5.3-chat-latest', | |
| 114 | + 'gpt-5.4', 'gpt-5.4-mini', 'gpt-5.4-nano', 'gpt-5.3-chat-latest', | |
| 190 | 115 | 'gpt-5.2', 'gpt-5.1-chat-latest', 'gpt-5.1-2025-11-13', 'gpt-5', 'gpt-5-mini', 'gpt-5-nano', |
| 191 | - 'custom-provider', | |
| 192 | 116 | ); |
| 193 | 117 | |
| 194 | 118 | //error_log('MXChat Save: in_array result: ' . (in_array($value, $allowed_models) ? 'YES' : 'NO')); |
| 195 | 119 | |
| @@ -446,11 +370,9 @@ | ||
| 446 | 370 | 'enable_streaming_toggle', |
| 447 | 371 | 'contextual_awareness_toggle', |
| 448 | 372 | 'citation_links_toggle', |
| 449 | 373 | 'enable_email_block', |
| 450 | - 'enable_name_field', | |
| 451 | - 'custom_provider_for_embeddings', | |
| 452 | - 'custom_provider_for_images' | |
| 374 | + 'enable_name_field' | |
| 453 | 375 | ])) { |
| 454 | 376 | //error_log('MXChat Save: Processing toggle: ' . $field_name); |
| 455 | 377 | $options[$field_name] = ($value === 'on') ? 'on' : 'off'; |
| 456 | 378 | } else { |