Plugin Directory

Changeset 3421683


Ignore:
Timestamp:
12/17/2025 09:37:27 AM (4 months ago)
Author:
wpiko
Message:
  • Added support for latest OpenAI models: GPT-5.1, GPT-5.1 Chat, GPT-5.2, and GPT-5.2 Chat
  • Added model information display with accurate specifications for all new models
Location:
wpiko-chatbot
Files:
68 added
6 edited

Legend:

Unmodified
Added
Removed
  • wpiko-chatbot/trunk/admin/js/models-info.js

    r3353266 r3421683  
    55 */
    66
    7 jQuery(document).ready(function($) {
     7jQuery(document).ready(function ($) {
    88    console.log('Models Info script loaded');
    9    
     9
    1010    // Model information data based on provided table
    1111    const modelsData = {
     12        'gpt-5.2': {
     13            displayName: 'GPT-5.2',
     14            description: 'The best model for coding and agentic tasks across industries',
     15            reasoning: 4,
     16            intelligence: null,
     17            speed: 4,
     18            contextWindow: '400,000',
     19            maxOutputTokens: '128,000',
     20            cost: 'Premium flagship +',
     21            badge: 'Latest'
     22        },
     23        'gpt-5.2-chat-latest': {
     24            displayName: 'GPT-5.2 Chat',
     25            description: 'GPT-5.2 model used in ChatGPT',
     26            reasoning: null,
     27            intelligence: 3,
     28            speed: 3,
     29            contextWindow: '128,000',
     30            maxOutputTokens: '16,384',
     31            cost: 'Premium flagship +',
     32            badge: 'Best Chat'
     33        },
     34        'gpt-5.1': {
     35            displayName: 'GPT-5.1',
     36            description: 'The best model for coding and agentic tasks with configurable reasoning effort',
     37            reasoning: 4,
     38            intelligence: null,
     39            speed: 4,
     40            contextWindow: '400,000',
     41            maxOutputTokens: '128,000',
     42            cost: 'Premium flagship',
     43            badge: 'Enhanced'
     44        },
     45        'gpt-5.1-chat-latest': {
     46            displayName: 'GPT-5.1 Chat',
     47            description: 'GPT-5.1 model used in ChatGPT',
     48            reasoning: null,
     49            intelligence: 3,
     50            speed: 3,
     51            contextWindow: '128,000',
     52            maxOutputTokens: '16,384',
     53            cost: 'Premium flagship',
     54            badge: 'Conversational'
     55        },
    1256        'gpt-5': {
    1357            displayName: 'GPT-5',
    1458            description: 'The best model for coding and agentic tasks across domains',
    1559            reasoning: 4,
    16             intelligence: 3,
     60            intelligence: null,
    1761            speed: 3,
    1862            contextWindow: '400,000',
     
    2569            description: 'A faster, cost-efficient version of GPT-5 for well-defined tasks',
    2670            reasoning: 3,
    27             intelligence: 4,
     71            intelligence: null,
    2872            speed: 4,
    2973            contextWindow: '400,000',
     
    3680            description: 'Fastest, most cost-efficient version of GPT-5',
    3781            reasoning: 2,
    38             intelligence: 5,
     82            intelligence: null,
    3983            speed: 5,
    4084            contextWindow: '400,000',
     
    135179                            </div>
    136180                            ` : ''}
    137                             ${modelKey.startsWith('gpt-4.1') ? `
     181                            ${model.intelligence !== null ? `
    138182                            <div class="wpiko-spec-item">
    139183                                <span class="wpiko-spec-label">Intelligence</span>
     
    180224    function updateModelInfo(selectedModel) {
    181225        let $modelInfoContainer = $('#wpiko-responses-model-info');
    182        
     226
    183227        if (!$modelInfoContainer.length) {
    184228            // Create the container if it doesn't exist
     
    206250    function initializeModelInfo() {
    207251        const $modelSelect = $('#responses_model');
    208        
     252
    209253        if ($modelSelect.length) {
    210254            // Show info for initially selected model
     
    215259
    216260            // Handle model selection changes
    217             $modelSelect.on('change', function() {
     261            $modelSelect.on('change', function () {
    218262                const selectedModel = $(this).val();
    219263                updateModelInfo(selectedModel);
    220                
     264
    221265                // Add a subtle animation
    222266                $('#wpiko-responses-model-info').hide().fadeIn(300);
     
    244288        // This could be expanded to show a comparison table of all models
    245289        // For now, we'll just expose the function for potential future use
    246         window.wpikoModelsComparison = function() {
     290        window.wpikoModelsComparison = function () {
    247291            const models = Object.keys(modelsData);
    248292            console.log('Available models for comparison:', models);
     
    256300    function initializeWhenResponsesVisible() {
    257301        const $responsesSection = $('#responses-api-settings');
    258        
     302
    259303        if ($responsesSection.is(':visible')) {
    260304            initializeModelInfo();
     
    262306
    263307        // Watch for API type changes
    264         $('input[name="api_type"]').on('change', function() {
     308        $('input[name="api_type"]').on('change', function () {
    265309            if ($(this).val() === 'responses' && $(this).is(':checked')) {
    266                 setTimeout(function() {
     310                setTimeout(function () {
    267311                    initializeModelInfo();
    268312                }, 100);
     
    271315
    272316        // Watch for save button that shows/hides sections
    273         $('#save_api_type').on('click', function() {
    274             setTimeout(function() {
     317        $('#save_api_type').on('click', function () {
     318            setTimeout(function () {
    275319                const $responsesSection = $('#responses-api-settings');
    276320                if ($responsesSection.is(':visible')) {
     
    287331    // Expose modelsData globally for debugging/development
    288332    window.wpikoModelsData = modelsData;
    289    
     333
    290334    // Add debug function for console testing
    291     window.wpikoDebugModels = function() {
     335    window.wpikoDebugModels = function () {
    292336        console.log('=== Wpiko Chatbot Models Debug Info ===');
    293337        console.log('Available models:', Object.keys(modelsData));
     
    297341        console.log('Full models data:', modelsData);
    298342    };
    299    
     343
    300344    // Log successful initialization
    301345    console.log('Wpiko Chatbot Models Info initialized with', Object.keys(modelsData).length, 'models');
  • wpiko-chatbot/trunk/admin/js/responses-api.js

    r3373160 r3421683  
    1 jQuery(document).ready(function($) {
    2    
     1jQuery(document).ready(function ($) {
     2
    33    // Handle System Instructions tab switching
    4     $('.instructions-tabs .nav-tab').on('click', function(e) {
     4    $('.instructions-tabs .nav-tab').on('click', function (e) {
    55        e.preventDefault();
    6        
     6
    77        var tabId = $(this).data('tab');
    8        
     8
    99        // Remove active class from all tabs and add to clicked tab
    1010        $('.instructions-tabs .nav-tab').removeClass('nav-tab-active');
    1111        $(this).addClass('nav-tab-active');
    12        
     12
    1313        // Hide all tab content and show the selected one
    1414        $('.tab-content').hide();
    1515        $('#' + tabId + '-tab').show();
    1616    });
    17    
     17
    1818    // Function to update main instructions dynamically for Responses API
    1919    function updateResponsesMainInstructions() {
     
    2323        var assistantTone = $('#responses_assistant_tone option:selected').text();
    2424        var assistantStyle = $('#responses_assistant_style option:selected').text();
    25        
     25
    2626        // NOTE: This instruction template is also defined in includes/instructions-handler.php
    2727        // If you modify this template, make sure to update both files to keep them in sync
    2828        var mainInstructions = "You are an " + assistantType + " for the website " + websiteName + ". " +
    29                              "The website specializes in " + websiteSpecialization + ". " +
    30                              "Your goal is to provide helpful, accurate, and engaging responses to user queries " +
    31                              "while maintaining a " + assistantTone + " and " + assistantStyle + " tone. " +
    32                              "Always respond as if you are a helpful member of the website team.";
    33        
     29            "The website specializes in " + websiteSpecialization + ". " +
     30            "Your goal is to provide helpful, accurate, and engaging responses to user queries " +
     31            "while maintaining a " + assistantTone + " and " + assistantStyle + " tone. " +
     32            "Always respond as if you are a helpful member of the website team.";
     33
    3434        $('#responses_main_system_instructions').val(mainInstructions);
    3535    }
    36    
     36
    3737    // Update instructions when fields change
    3838    $('#responses_website_specialization').on('input', updateResponsesMainInstructions);
     
    4141    $('#responses_assistant_tone').on('change', updateResponsesMainInstructions);
    4242    $('#responses_assistant_style').on('change', updateResponsesMainInstructions);
    43    
     43
    4444    // Initialize instructions on page load
    4545    updateResponsesMainInstructions();
    46    
     46
    4747    // Handle Vector Store refresh
    48     $(document).on('click', '.vector-store-refresh-btn', function(e) {
     48    $(document).on('click', '.vector-store-refresh-btn', function (e) {
    4949        e.preventDefault();
    50        
     50
    5151        var $button = $(this);
    5252        var $vectorStoreInfo = $button.closest('.vector-store-info');
    53        
     53
    5454        // Disable button and show loading state
    5555        $button.prop('disabled', true);
    5656        var $icon = $button.find('.dashicons');
    5757        $icon.css('animation', 'rotation 1s infinite linear');
    58        
     58
    5959        $.ajax({
    6060            url: wpikoChatbotAdmin.ajax_url,
     
    6464                security: wpikoChatbotAdmin.nonce
    6565            },
    66             success: function(response) {
     66            success: function (response) {
    6767                if (response.success && response.data) {
    6868                    var data = response.data;
     
    7878                    var statusClass = status === 'completed' ? 'status-active' : 'status-processing';
    7979                    var statusText = status.charAt(0).toUpperCase() + status.slice(1);
    80                    
     80
    8181                    // Update the Vector Store information
    8282                    var html = '<div class="vector-store-header">' +
     
    113113                        '</div>' +
    114114                        '</div>';
    115                    
     115
    116116                    $vectorStoreInfo.removeClass('vector-store-error').html(html);
    117117                } else if (response.data && response.data.not_found) {
     
    138138                        '<p>A new Vector Store will be automatically created when you upload your first file.</p>' +
    139139                        '</div>';
    140                    
     140
    141141                    $vectorStoreInfo.addClass('vector-store-error').html(html);
    142142                } else {
     
    144144                }
    145145            },
    146             error: function() {
     146            error: function () {
    147147                alert('Connection error occurred while trying to refresh Vector Store information.');
    148148            },
    149             complete: function() {
     149            complete: function () {
    150150                // Re-enable button and stop animation
    151151                $button.prop('disabled', false);
     
    154154        });
    155155    });
    156    
     156
    157157    // Handle Vector Store deletion
    158     $(document).on('click', '.vector-store-delete-btn', function(e) {
     158    $(document).on('click', '.vector-store-delete-btn', function (e) {
    159159        e.preventDefault();
    160        
     160
    161161        var confirmed = confirm(
    162162            'Are you sure you want to delete the Vector Store?\n\n' +
     
    168168            'Click OK to delete or Cancel to keep it.'
    169169        );
    170        
     170
    171171        if (!confirmed) {
    172172            return;
    173173        }
    174        
     174
    175175        var $button = $(this);
    176176        var $vectorStoreInfo = $button.closest('.vector-store-info');
    177        
     177
    178178        // Disable button and show loading state
    179179        $button.prop('disabled', true);
    180180        $button.find('.dashicons').removeClass('dashicons-trash').addClass('dashicons-update').css('animation', 'rotation 1s infinite linear');
    181        
     181
    182182        $.ajax({
    183183            url: wpikoChatbotAdmin.ajax_url,
     
    187187                security: wpikoChatbotAdmin.nonce
    188188            },
    189             success: function(response) {
     189            success: function (response) {
    190190                if (response.success) {
    191191                    var message = response.data.message || 'Vector Store has been deleted.';
     
    196196                        '</div>'
    197197                    );
    198                    
     198
    199199                    // Reload page after 2 seconds
    200                     setTimeout(function() {
     200                    setTimeout(function () {
    201201                        location.reload();
    202202                    }, 2000);
     
    207207                }
    208208            },
    209             error: function() {
     209            error: function () {
    210210                alert('Connection error occurred while trying to delete the Vector Store.');
    211211                $button.prop('disabled', false);
     
    214214        });
    215215    });
    216    
     216
    217217    // Handle Responses API configuration save
    218     $('#save_responses_config').on('click', function() {
     218    $('#save_responses_config').on('click', function () {
    219219        var $button = $(this);
    220220        var $status = $('#responses_save_status');
    221        
     221
    222222        $button.prop('disabled', true).text('Saving...');
    223223        $status.removeClass('success error').addClass('info').text('Saving configuration...');
    224        
     224
    225225        var data = {
    226226            action: 'wpiko_chatbot_update_responses_config',
     
    237237            orders_system_instructions: $('#responses_orders_system_instructions').val()
    238238        };
    239        
    240         $.post(wpikoChatbotAdmin.ajax_url, data, function(response) {
     239
     240        $.post(wpikoChatbotAdmin.ajax_url, data, function (response) {
    241241            if (response.success) {
    242242                $status.removeClass('error info').addClass('success').text('Configuration saved successfully!');
    243                 setTimeout(function() {
    244                     $status.removeClass('success error info').text(''); 
     243                setTimeout(function () {
     244                    $status.removeClass('success error info').text('');
    245245                }, 3000);
    246246            } else {
    247247                $status.removeClass('success info').addClass('error').text('Error: ' + response.data.message);
    248248            }
    249         }).fail(function() {
     249        }).fail(function () {
    250250            $status.removeClass('success info').addClass('error').text('Connection error occurred.');
    251         }).always(function() {
     251        }).always(function () {
    252252            $button.prop('disabled', false).text('Save Configuration');
    253253        });
     
    255255
    256256    // Handle model selection changes to show model information
    257     $('#responses_model').on('change', function() {
     257    $('#responses_model').on('change', function () {
    258258        var selectedModel = $(this).val();
    259        
     259
    260260        // Remove any existing model info
    261261        $('#responses_model').next('.model-info').remove();
    262        
     262
    263263        // Model information based on the provided documentation
    264264        var modelInfo = '';
    265         switch(selectedModel) {
     265        switch (selectedModel) {
    266266            case 'gpt-4.1':
    267                 modelInfo = '<div class="model-info"><p><strong>GPT-4.1:</strong> Latest high-performance model with enhanced reasoning capabilities and tool support. Ideal for complex tasks requiring deep analysis.</p></div>';
     267                modelInfo = '<div class="model-info"><p><strong>GPT-4.1:</strong> High-performance model with enhanced capabilities and tool support. Ideal for complex tasks.</p></div>';
    268268                break;
    269269            case 'gpt-4.1-mini':
     
    280280                break;
    281281            case 'gpt-5-nano':
    282                 modelInfo = '<div class="model-info"><p><strong>GPT-5 Nano:</strong> Efficient GPT-5 variant optimized for speed and cost-effectiveness while maintaining quality responses.</p></div>';
     282                modelInfo = '<div class=\"model-info\"><p><strong>GPT-5 Nano:</strong> Efficient GPT-5 variant optimized for speed and cost-effectiveness while maintaining quality responses.</p></div>';
     283                break;
     284            case 'gpt-5.1':
     285                modelInfo = '<div class=\"model-info\"><p><strong>GPT-5.1:</strong> Enhanced GPT-5 with improved intelligence and better instruction-following capabilities. </p></div>';
     286                break;
     287            case 'gpt-5.1-chat-latest':
     288                modelInfo = '<div class=\"model-info\"><p><strong>GPT-5.1 Chat:</strong> Optimized for natural conversations with warmer, more engaging responses.</p></div>';
     289                break;
     290            case 'gpt-5.2':
     291                modelInfo = '<div class=\"model-info\"><p><strong>GPT-5.2:</strong> Most capable model for professional knowledge work. </p></div>';
     292                break;
     293            case 'gpt-5.2-chat-latest':
     294                modelInfo = '<div class=\"model-info\"><p><strong>GPT-5.2 Chat:</strong> Latest conversational model with superior quality and trustworthiness.</p></div>';
    283295                break;
    284296        }
    285        
     297
    286298        if (modelInfo) {
    287299            $(this).after(modelInfo);
    288300        }
    289301    });
    290    
     302
    291303    // Trigger model info display on page load
    292304    $('#responses_model').trigger('change');
  • wpiko-chatbot/trunk/admin/sections/ai-configuration-section.php

    r3373160 r3421683  
    44}
    55
    6 function wpiko_chatbot_ai_configuration_section() {
     6function wpiko_chatbot_ai_configuration_section()
     7{
    78
    89    if (isset($_POST['action']) && $_POST['action'] == 'save_ai_configuration') {
    910        check_admin_referer('save_ai_configuration', 'ai_configuration_nonce');
    10        
     11
    1112        // Update Responses API settings
    1213        if (isset($_POST['responses_model'])) {
    1314            update_option('wpiko_chatbot_responses_model', sanitize_text_field(wp_unslash($_POST['responses_model'])));
    1415        }
    15        
     16
    1617        echo '<div class="updated"><p>AI Configuration updated successfully.</p></div>';
    1718    }
    18    
     19
    1920    $responses_model = get_option('wpiko_chatbot_responses_model', 'gpt-4.1-mini');
    2021    ?>
    2122    <div class="ai-configuration-section">
    22        
    23         <?php 
     23
     24        <?php
    2425        // Action hook for adding content after AI configuration title (e.g., WooCommerce integration state)
    2526        do_action('wpiko_chatbot_after_ai_configuration_title');
    2627        ?>
    27        
     28
    2829        <form method="post" action="" name="ai_configuration_form" id="ai_configuration_form">
    2930            <?php wp_nonce_field('save_ai_configuration', 'ai_configuration_nonce'); ?>
    30            
    31     <!-- Responses API Settings -->
    32     <div id="responses-api-settings" style="display: block;">
    33         <div class="responses-api-section">
    34             <h3><span class="dashicons dashicons-admin-generic"></span> AI Configuration</h3>
    35             <p class="description">Set up your AI chatbot settings to customize how it interacts with your website visitors.</p>
    36            
    37             <table class="form-table">
    38                 <tr valign="top">
    39                     <th scope="row">Model</th>
    40                     <td>
    41                         <select name="responses_model" id="responses_model">
    42                             <?php
    43                             // Latest models only (per provided documentation)
    44                             $available_models = array(
    45                                 'gpt-4.1' => 'GPT-4.1',
    46                                 'gpt-4.1-mini' => 'GPT-4.1 Mini',
    47                                 'gpt-4.1-nano' => 'GPT-4.1 Nano',
    48                                 'gpt-5' => 'GPT-5',
    49                                 'gpt-5-mini' => 'GPT-5 Mini',
    50                                 'gpt-5-nano' => 'GPT-5 Nano'
    51                             );
    52                             foreach ($available_models as $model_value => $model_label) {
    53                                 printf('<option value="%s" %s>%s</option>',
    54                                     esc_attr($model_value),
    55                                     selected($model_value, $responses_model, false),
    56                                     esc_html($model_label)
    57                                 );
    58                             }
    59                             ?>
    60                         </select>
    61                        
    62                         <!-- Dynamic model information will be inserted here by JavaScript -->
    63                         <div id="wpiko-responses-model-info"></div>
    64                         <p class="description">Select one of the latest OpenAI models. Detailed information will appear when you select a model.</p>
    65                     </td>
    66                 </tr>
    67                 <tr valign="top">
    68                     <th scope="row">System Instructions</th>
    69                     <td>
    70                         <div class="instructions-tabs">
    71                             <ul class="nav-tab-wrapper">
    72                                 <li><a href="#" class="nav-tab nav-tab-active" data-tab="responses-basic">Basic Instructions</a></li>
    73                                 <li><a href="#" class="nav-tab" data-tab="responses-advanced">Advanced Instructions</a></li>
    74                             </ul>
    75 
    76                             <div class="tab-content" id="responses-basic-tab" style="display: block;">
    77                                 <table class="form-table">
    78                                     <tr valign="top">
    79                                         <td>
    80                                             <div class="structured-instructions">
    81                                            
    82                                                 <div class="instruction-field assistant-type-field">
    83                                                     <label>You are an</label>
    84                                                     <input type="text" name="responses_assistant_type" id="responses_assistant_type" class="medium-text"
    85                                                         value="<?php echo esc_attr(get_option('wpiko_chatbot_responses_assistant_type', get_option('wpiko_chatbot_assistant_type', 'AI assistant'))); ?>"
    86                                                         placeholder="AI assistant">
    87                                                     <span>for the website <strong class="website-name"><?php echo esc_html(get_bloginfo('name')); ?></strong>.</span>
    88                                                 </div>
    89 
    90                                                 <div class="instruction-field">
    91                                                     <label>The website specializes in:</label>
    92                                                     <input type="text" name="responses_website_specialization" id="responses_website_specialization" class="medium-text"
    93                                                         value="<?php echo esc_attr(get_option('wpiko_chatbot_responses_website_specialization', get_option('wpiko_chatbot_website_specialization', ''))); ?>"
    94                                                         placeholder="e.g., web development, digital marketing, etc.">
    95                                                 </div>
    96 
    97                                                 <div class="instruction-field">
    98                                                     <label>Assistant Tone:</label>
    99                                                     <select name="responses_assistant_tone" id="responses_assistant_tone">
    100                                                         <?php
    101                                                         $tones = array(
    102                                                             'friendly' => 'Friendly',
    103                                                             'casual' => 'Casual',
    104                                                             'professional' => 'Professional',
    105                                                             'formal' => 'Formal',
    106                                                             'humorous' => 'Humorous',
    107                                                             'educational' => 'Educational',
    108                                                             'enthusiastic' => 'Enthusiastic'
    109                                                         );
    110                                                         $selected_tone = get_option('wpiko_chatbot_responses_assistant_tone', get_option('wpiko_chatbot_assistant_tone', 'friendly'));
    111                                                         foreach ($tones as $value => $label) {
    112                                                             printf('<option value="%s" %s>%s</option>',
    113                                                                 esc_attr($value),
    114                                                                 selected($value, $selected_tone, false),
    115                                                                 esc_html($label)
    116                                                             );
    117                                                         }
    118                                                         ?>
    119                                                     </select>
    120                                                 </div>
    121 
    122                                                 <div class="instruction-field">
    123                                                     <label>Assistant Style:</label>
    124                                                     <select name="responses_assistant_style" id="responses_assistant_style">
    125                                                         <?php
    126                                                         $styles = array(
    127                                                             'professional' => 'Professional',
    128                                                             'conversational' => 'Conversational',
    129                                                             'helpful' => 'Helpful',
    130                                                             'concise' => 'Concise',
    131                                                             'detailed' => 'Detailed'
    132                                                         );
    133                                                         $selected_style = get_option('wpiko_chatbot_responses_assistant_style', get_option('wpiko_chatbot_assistant_style', 'professional'));
    134                                                         foreach ($styles as $value => $label) {
    135                                                             printf('<option value="%s" %s>%s</option>',
    136                                                                 esc_attr($value),
    137                                                                 selected($value, $selected_style, false),
    138                                                                 esc_html($label)
    139                                                             );
    140                                                         }
    141                                                         ?>
    142                                                     </select>
    143                                                 </div>
    144                                             </div>
    145                                             <input type="hidden" name="responses_main_system_instructions" id="responses_main_system_instructions" value="<?php
    146                                                 $instructions = wpiko_chatbot_get_system_instructions();
    147                                                 echo esc_attr($instructions['main']);
    148                                             ?>">
    149                                             <p class="description">Customize how your AI assistant introduces itself and understands your website's purpose and content.</p>
    150                                         </td>
    151                                     </tr>
    152                                 </table>
     31
     32            <!-- Responses API Settings -->
     33            <div id="responses-api-settings" style="display: block;">
     34                <div class="responses-api-section">
     35                    <h3><span class="dashicons dashicons-admin-generic"></span> AI Configuration</h3>
     36                    <p class="description">Set up your AI chatbot settings to customize how it interacts with your website
     37                        visitors.</p>
     38
     39                    <table class="form-table">
     40                        <tr valign="top">
     41                            <th scope="row">Model</th>
     42                            <td>
     43                                <select name="responses_model" id="responses_model">
     44                                    <?php
     45                                    // Latest models only (per provided documentation)
     46                                    $available_models = array(
     47                                        'gpt-4.1' => 'GPT-4.1',
     48                                        'gpt-4.1-mini' => 'GPT-4.1 Mini',
     49                                        'gpt-4.1-nano' => 'GPT-4.1 Nano',
     50                                        'gpt-5' => 'GPT-5',
     51                                        'gpt-5-mini' => 'GPT-5 Mini',
     52                                        'gpt-5-nano' => 'GPT-5 Nano',
     53                                        'gpt-5.1' => 'GPT-5.1',
     54                                        'gpt-5.1-chat-latest' => 'GPT-5.1 Chat',
     55                                        'gpt-5.2' => 'GPT-5.2',
     56                                        'gpt-5.2-chat-latest' => 'GPT-5.2 Chat'
     57                                    );
     58                                    foreach ($available_models as $model_value => $model_label) {
     59                                        printf(
     60                                            '<option value="%s" %s>%s</option>',
     61                                            esc_attr($model_value),
     62                                            selected($model_value, $responses_model, false),
     63                                            esc_html($model_label)
     64                                        );
     65                                    }
     66                                    ?>
     67                                </select>
     68
     69                                <!-- Dynamic model information will be inserted here by JavaScript -->
     70                                <div id="wpiko-responses-model-info"></div>
     71                                <p class="description">Select one of the latest OpenAI models. Detailed information will
     72                                    appear when you select a model.</p>
     73                            </td>
     74                        </tr>
     75                        <tr valign="top">
     76                            <th scope="row">System Instructions</th>
     77                            <td>
     78                                <div class="instructions-tabs">
     79                                    <ul class="nav-tab-wrapper">
     80                                        <li><a href="#" class="nav-tab nav-tab-active" data-tab="responses-basic">Basic
     81                                                Instructions</a></li>
     82                                        <li><a href="#" class="nav-tab" data-tab="responses-advanced">Advanced
     83                                                Instructions</a></li>
     84                                    </ul>
     85
     86                                    <div class="tab-content" id="responses-basic-tab" style="display: block;">
     87                                        <table class="form-table">
     88                                            <tr valign="top">
     89                                                <td>
     90                                                    <div class="structured-instructions">
     91
     92                                                        <div class="instruction-field assistant-type-field">
     93                                                            <label>You are an</label>
     94                                                            <input type="text" name="responses_assistant_type"
     95                                                                id="responses_assistant_type" class="medium-text"
     96                                                                value="<?php echo esc_attr(get_option('wpiko_chatbot_responses_assistant_type', get_option('wpiko_chatbot_assistant_type', 'AI assistant'))); ?>"
     97                                                                placeholder="AI assistant">
     98                                                            <span>for the website <strong
     99                                                                    class="website-name"><?php echo esc_html(get_bloginfo('name')); ?></strong>.</span>
     100                                                        </div>
     101
     102                                                        <div class="instruction-field">
     103                                                            <label>The website specializes in:</label>
     104                                                            <input type="text" name="responses_website_specialization"
     105                                                                id="responses_website_specialization" class="medium-text"
     106                                                                value="<?php echo esc_attr(get_option('wpiko_chatbot_responses_website_specialization', get_option('wpiko_chatbot_website_specialization', ''))); ?>"
     107                                                                placeholder="e.g., web development, digital marketing, etc.">
     108                                                        </div>
     109
     110                                                        <div class="instruction-field">
     111                                                            <label>Assistant Tone:</label>
     112                                                            <select name="responses_assistant_tone"
     113                                                                id="responses_assistant_tone">
     114                                                                <?php
     115                                                                $tones = array(
     116                                                                    'friendly' => 'Friendly',
     117                                                                    'casual' => 'Casual',
     118                                                                    'professional' => 'Professional',
     119                                                                    'formal' => 'Formal',
     120                                                                    'humorous' => 'Humorous',
     121                                                                    'educational' => 'Educational',
     122                                                                    'enthusiastic' => 'Enthusiastic'
     123                                                                );
     124                                                                $selected_tone = get_option('wpiko_chatbot_responses_assistant_tone', get_option('wpiko_chatbot_assistant_tone', 'friendly'));
     125                                                                foreach ($tones as $value => $label) {
     126                                                                    printf(
     127                                                                        '<option value="%s" %s>%s</option>',
     128                                                                        esc_attr($value),
     129                                                                        selected($value, $selected_tone, false),
     130                                                                        esc_html($label)
     131                                                                    );
     132                                                                }
     133                                                                ?>
     134                                                            </select>
     135                                                        </div>
     136
     137                                                        <div class="instruction-field">
     138                                                            <label>Assistant Style:</label>
     139                                                            <select name="responses_assistant_style"
     140                                                                id="responses_assistant_style">
     141                                                                <?php
     142                                                                $styles = array(
     143                                                                    'professional' => 'Professional',
     144                                                                    'conversational' => 'Conversational',
     145                                                                    'helpful' => 'Helpful',
     146                                                                    'concise' => 'Concise',
     147                                                                    'detailed' => 'Detailed'
     148                                                                );
     149                                                                $selected_style = get_option('wpiko_chatbot_responses_assistant_style', get_option('wpiko_chatbot_assistant_style', 'professional'));
     150                                                                foreach ($styles as $value => $label) {
     151                                                                    printf(
     152                                                                        '<option value="%s" %s>%s</option>',
     153                                                                        esc_attr($value),
     154                                                                        selected($value, $selected_style, false),
     155                                                                        esc_html($label)
     156                                                                    );
     157                                                                }
     158                                                                ?>
     159                                                            </select>
     160                                                        </div>
     161                                                    </div>
     162                                                    <input type="hidden" name="responses_main_system_instructions"
     163                                                        id="responses_main_system_instructions" value="<?php
     164                                                        $instructions = wpiko_chatbot_get_system_instructions();
     165                                                        echo esc_attr($instructions['main']);
     166                                                        ?>">
     167                                                    <p class="description">Customize how your AI assistant introduces itself
     168                                                        and understands your website's purpose and content.</p>
     169                                                </td>
     170                                            </tr>
     171                                        </table>
     172                                    </div>
     173
     174                                    <div class="tab-content" id="responses-advanced-tab" style="display: none;">
     175                                        <table class="form-table">
     176                                            <tr valign="top">
     177                                                <th scope="row">Specific System Instructions</th>
     178                                                <td>
     179                                                    <textarea name="responses_specific_system_instructions"
     180                                                        id="responses_specific_system_instructions" class="large-text"
     181                                                        rows="5" placeholder="Examples:
     182Keep responses under 3 sentences when possible.
     183For support inquiries, direct users to contact@example.com.">    <?php
     184    $instructions = wpiko_chatbot_get_system_instructions();
     185    echo esc_textarea($instructions['specific']);
     186    ?></textarea>
     187                                                    <p class="description">Enter specific rules and guidelines for how your
     188                                                        assistant should behave and respond.</p>
     189                                                </td>
     190                                            </tr>
     191                                            <tr valign="top">
     192                                                <th scope="row">Knowledge System Instructions</th>
     193                                                <td>
     194                                                    <textarea name="responses_knowledge_system_instructions"
     195                                                        id="responses_knowledge_system_instructions" class="large-text"
     196                                                        rows="5"><?php
     197                                                        echo esc_textarea($instructions['knowledge']);
     198                                                        ?></textarea>
     199                                                    <p class="description">Edit knowledge-related system instructions for
     200                                                        your assistant only if necessary. These instructions help the AI
     201                                                        understand how to use uploaded files and knowledge base.</p>
     202                                                </td>
     203                                            </tr>
     204                                            <?php
     205                                            // Action hook for adding advanced system instructions (e.g., WooCommerce products/orders instructions)
     206                                            do_action('wpiko_chatbot_responses_advanced_system_instructions');
     207                                            ?>
     208                                        </table>
     209                                    </div>
     210                                </div>
     211                            </td>
     212                        </tr>
     213                        <tr valign="top">
     214                            <th scope="row">Save Configuration</th>
     215                            <td>
     216                                <button type="button" id="save_responses_config" class="button button-primary">Save
     217                                    Configuration</button>
     218                                <span id="responses_save_status"></span>
     219                            </td>
     220                        </tr>
     221
     222                    </table>
     223                </div>
     224
     225                <!-- Responses Actions Section -->
     226                <div id="responses-actions-section" style="display: block;">
     227                    <h3><span class="dashicons dashicons-admin-tools"></span> Train AI Assistant</h3>
     228                    <p class="description">Deliver better user experiences by shaping your AI assistant's knowledge.</p>
     229
     230                    <?php
     231                    // Display Vector Store Information
     232                    $vector_store_details = wpiko_chatbot_get_responses_vector_store_details();
     233                    if ($vector_store_details['success']) {
     234                        $created_date = !empty($vector_store_details['created_at']) ? date('F j, Y', $vector_store_details['created_at']) : 'N/A';
     235                        $file_counts = $vector_store_details['file_counts'] ?? array();
     236                        $total_files = isset($file_counts['total']) ? $file_counts['total'] : 0;
     237                        $completed_files = isset($file_counts['completed']) ? $file_counts['completed'] : 0;
     238                        $status = $vector_store_details['status'] ?? 'unknown';
     239                        $status_class = $status === 'completed' ? 'status-active' : 'status-processing';
     240                        $status_text = ucfirst($status);
     241                        ?>
     242                        <div class="vector-store-info">
     243                            <div class="vector-store-header">
     244                                <span class="dashicons dashicons-database"></span>
     245                                <h4>Vector Store Information
     246                                    <span class="vector-store-info-icon"
     247                                        title="A Vector Store is a specialized database in OpenAI that stores and indexes your uploaded files (PDFs, documents, etc.) for semantic search. It enables your AI chatbot to search through your knowledge base and provide accurate answers based on your content.">
     248                                        <span class="dashicons dashicons-info"></span>
     249                                    </span>
     250                                </h4>
     251                                <span
     252                                    class="vector-store-status <?php echo esc_attr($status_class); ?>"><?php echo esc_html($status_text); ?></span>
     253                                <button type="button" class="button button-link-refresh vector-store-refresh-btn"
     254                                    title="Refresh Vector Store Information">
     255                                    <span class="dashicons dashicons-update"></span>
     256                                </button>
     257                                <button type="button" class="button button-link-delete vector-store-delete-btn"
     258                                    title="Delete Vector Store and All Files">
     259                                    <span class="dashicons dashicons-trash"></span>
     260                                </button>
    153261                            </div>
    154 
    155                             <div class="tab-content" id="responses-advanced-tab" style="display: none;">
    156                                 <table class="form-table">
    157                                     <tr valign="top">
    158                                         <th scope="row">Specific System Instructions</th>
    159                                         <td>
    160                                             <textarea name="responses_specific_system_instructions" id="responses_specific_system_instructions" class="large-text" rows="5" placeholder="Examples:
    161 Keep responses under 3 sentences when possible.
    162 For support inquiries, direct users to contact@example.com."><?php
    163                                                 $instructions = wpiko_chatbot_get_system_instructions();
    164                                                 echo esc_textarea($instructions['specific']);
    165                                             ?></textarea>
    166                                             <p class="description">Enter specific rules and guidelines for how your assistant should behave and respond.</p>
    167                                         </td>
    168                                     </tr>
    169                                     <tr valign="top">
    170                                         <th scope="row">Knowledge System Instructions</th>
    171                                         <td>
    172                                             <textarea name="responses_knowledge_system_instructions" id="responses_knowledge_system_instructions" class="large-text" rows="5"><?php
    173                                                 echo esc_textarea($instructions['knowledge']);
    174                                             ?></textarea>
    175                                             <p class="description">Edit knowledge-related system instructions for your assistant only if necessary. These instructions help the AI understand how to use uploaded files and knowledge base.</p>
    176                                         </td>
    177                                     </tr>
    178                                     <?php
    179                                     // Action hook for adding advanced system instructions (e.g., WooCommerce products/orders instructions)
    180                                     do_action('wpiko_chatbot_responses_advanced_system_instructions');
    181                                     ?>
    182                                 </table>
     262                            <div class="vector-store-details">
     263                                <div class="vector-store-item">
     264                                    <strong>Name:</strong>
     265                                    <span><?php echo esc_html($vector_store_details['name']); ?></span>
     266                                </div>
     267                                <div class="vector-store-item">
     268                                    <strong>ID:</strong>
     269                                    <code class="vector-store-id"><?php echo esc_html($vector_store_details['id']); ?></code>
     270                                </div>
     271                                <div class="vector-store-item">
     272                                    <strong>Created:</strong>
     273                                    <span><?php echo esc_html($created_date); ?></span>
     274                                </div>
     275                                <div class="vector-store-item">
     276                                    <strong>Files:</strong>
     277                                    <span><?php echo esc_html($completed_files . ' completed / ' . $total_files . ' total'); ?></span>
     278                                </div>
    183279                            </div>
    184280                        </div>
    185                     </td>
    186                 </tr>
    187                 <tr valign="top">
    188                     <th scope="row">Save Configuration</th>
    189                     <td>
    190                         <button type="button" id="save_responses_config" class="button button-primary">Save Configuration</button>
    191                         <span id="responses_save_status"></span>
    192                     </td>
    193                 </tr>
    194                
    195             </table>
    196         </div>
    197 
    198         <!-- Responses Actions Section -->
    199         <div id="responses-actions-section" style="display: block;">
    200             <h3><span class="dashicons dashicons-admin-tools"></span> Train AI Assistant</h3>
    201             <p class="description">Deliver better user experiences by shaping your AI assistant's knowledge.</p>
    202            
    203             <?php
    204             // Display Vector Store Information
    205             $vector_store_details = wpiko_chatbot_get_responses_vector_store_details();
    206             if ($vector_store_details['success']) {
    207                 $created_date = !empty($vector_store_details['created_at']) ? date('F j, Y', $vector_store_details['created_at']) : 'N/A';
    208                 $file_counts = $vector_store_details['file_counts'] ?? array();
    209                 $total_files = isset($file_counts['total']) ? $file_counts['total'] : 0;
    210                 $completed_files = isset($file_counts['completed']) ? $file_counts['completed'] : 0;
    211                 $status = $vector_store_details['status'] ?? 'unknown';
    212                 $status_class = $status === 'completed' ? 'status-active' : 'status-processing';
    213                 $status_text = ucfirst($status);
    214                 ?>
    215                 <div class="vector-store-info">
    216                     <div class="vector-store-header">
    217                         <span class="dashicons dashicons-database"></span>
    218                         <h4>Vector Store Information
    219                             <span class="vector-store-info-icon" title="A Vector Store is a specialized database in OpenAI that stores and indexes your uploaded files (PDFs, documents, etc.) for semantic search. It enables your AI chatbot to search through your knowledge base and provide accurate answers based on your content.">
    220                                 <span class="dashicons dashicons-info"></span>
    221                             </span>
    222                         </h4>
    223                         <span class="vector-store-status <?php echo esc_attr($status_class); ?>"><?php echo esc_html($status_text); ?></span>
    224                         <button type="button" class="button button-link-refresh vector-store-refresh-btn" title="Refresh Vector Store Information">
    225                             <span class="dashicons dashicons-update"></span>
     281                    <?php } elseif (isset($vector_store_details['not_found']) && $vector_store_details['not_found']) {
     282                        // Vector Store was deleted from OpenAI dashboard
     283                        ?>
     284                        <div class="vector-store-info vector-store-error">
     285                            <div class="vector-store-header">
     286                                <span class="dashicons dashicons-warning"></span>
     287                                <h4>Vector Store Not Found
     288                                    <span class="vector-store-info-icon"
     289                                        title="A Vector Store is a specialized database in OpenAI that stores and indexes your uploaded files (PDFs, documents, etc.) for semantic search. It enables your AI chatbot to search through your knowledge base and provide accurate answers based on your content.">
     290                                        <span class="dashicons dashicons-info"></span>
     291                                    </span>
     292                                </h4>
     293                                <span class="vector-store-status status-error">Error</span>
     294                                <button type="button" class="button button-link-refresh vector-store-refresh-btn"
     295                                    title="Refresh Vector Store Information">
     296                                    <span class="dashicons dashicons-update"></span>
     297                                </button>
     298                            </div>
     299                            <div class="vector-store-error-message">
     300                                <p><strong>The Vector Store was deleted or is no longer accessible.</strong></p>
     301                                <p>This may have happened if you deleted it from the OpenAI dashboard. To fix this issue:</p>
     302                                <ol>
     303                                    <li>Upload a new file using the "File Management" button below, or</li>
     304                                    <li>Use any of the training tools (Scan Website, Q&A Builder, etc.)</li>
     305                                </ol>
     306                                <p>A new Vector Store will be automatically created when you upload your first file.</p>
     307                            </div>
     308                        </div>
     309                    <?php } ?>
     310
     311                    <div class="assistant-action-buttons">
     312                        <button type="button" class="button button-secondary wpiko-file-management-button">
     313                            <span class="dashicons dashicons-upload"></span> File Management
    226314                        </button>
    227                         <button type="button" class="button button-link-delete vector-store-delete-btn" title="Delete Vector Store and All Files">
    228                             <span class="dashicons dashicons-trash"></span>
    229                         </button>
     315
     316                        <?php
     317                        // Check if additional response actions are available
     318                        if (has_action('wpiko_chatbot_responses_scan_website_button')): ?>
     319                            <?php do_action('wpiko_chatbot_responses_scan_website_button'); ?>
     320                            <?php do_action('wpiko_chatbot_responses_qa_builder_button'); ?>
     321
     322                            <?php if (wpiko_chatbot_is_woocommerce_active()): ?>
     323                                <?php do_action('wpiko_chatbot_responses_woocommerce_integration_button'); ?>
     324                            <?php endif; ?>
     325                        <?php endif; ?>
    230326                    </div>
    231                     <div class="vector-store-details">
    232                         <div class="vector-store-item">
    233                             <strong>Name:</strong>
    234                             <span><?php echo esc_html($vector_store_details['name']); ?></span>
    235                         </div>
    236                         <div class="vector-store-item">
    237                             <strong>ID:</strong>
    238                             <code class="vector-store-id"><?php echo esc_html($vector_store_details['id']); ?></code>
    239                         </div>
    240                         <div class="vector-store-item">
    241                             <strong>Created:</strong>
    242                             <span><?php echo esc_html($created_date); ?></span>
    243                         </div>
    244                         <div class="vector-store-item">
    245                             <strong>Files:</strong>
    246                             <span><?php echo esc_html($completed_files . ' completed / ' . $total_files . ' total'); ?></span>
    247                         </div>
    248                     </div>
     327
     328                    <!-- Modal container for file management is defined globally below -->
     329
     330                    <?php
     331                    // Check if additional response modal actions are available
     332                    if (has_action('wpiko_chatbot_responses_scan_website_modal')): ?>
     333                        <?php do_action('wpiko_chatbot_responses_scan_website_modal'); ?>
     334                        <?php do_action('wpiko_chatbot_responses_qa_builder_modal'); ?>
     335                        <?php do_action('wpiko_chatbot_responses_woocommerce_integration_modal'); ?>
     336                    <?php endif; ?>
    249337                </div>
    250             <?php } elseif (isset($vector_store_details['not_found']) && $vector_store_details['not_found']) {
    251                 // Vector Store was deleted from OpenAI dashboard
    252                 ?>
    253                 <div class="vector-store-info vector-store-error">
    254                     <div class="vector-store-header">
    255                         <span class="dashicons dashicons-warning"></span>
    256                         <h4>Vector Store Not Found
    257                             <span class="vector-store-info-icon" title="A Vector Store is a specialized database in OpenAI that stores and indexes your uploaded files (PDFs, documents, etc.) for semantic search. It enables your AI chatbot to search through your knowledge base and provide accurate answers based on your content.">
    258                                 <span class="dashicons dashicons-info"></span>
    259                             </span>
    260                         </h4>
    261                         <span class="vector-store-status status-error">Error</span>
    262                         <button type="button" class="button button-link-refresh vector-store-refresh-btn" title="Refresh Vector Store Information">
    263                             <span class="dashicons dashicons-update"></span>
    264                         </button>
    265                     </div>
    266                     <div class="vector-store-error-message">
    267                         <p><strong>The Vector Store was deleted or is no longer accessible.</strong></p>
    268                         <p>This may have happened if you deleted it from the OpenAI dashboard. To fix this issue:</p>
    269                         <ol>
    270                             <li>Upload a new file using the "File Management" button below, or</li>
    271                             <li>Use any of the training tools (Scan Website, Q&A Builder, etc.)</li>
    272                         </ol>
    273                         <p>A new Vector Store will be automatically created when you upload your first file.</p>
    274                     </div>
    275                 </div>
    276             <?php } ?>
    277            
    278             <div class="assistant-action-buttons">
    279                 <button type="button" class="button button-secondary wpiko-file-management-button">
    280                     <span class="dashicons dashicons-upload"></span> File Management
    281                 </button>
    282                
    283                 <?php
    284                 // Check if additional response actions are available
    285                 if (has_action('wpiko_chatbot_responses_scan_website_button')): ?>
    286                     <?php do_action('wpiko_chatbot_responses_scan_website_button'); ?>
    287                     <?php do_action('wpiko_chatbot_responses_qa_builder_button'); ?>
    288                    
    289                     <?php if (wpiko_chatbot_is_woocommerce_active()): ?>
    290                         <?php do_action('wpiko_chatbot_responses_woocommerce_integration_button'); ?>
    291                     <?php endif; ?>
    292                 <?php endif; ?>
    293338            </div>
    294339
    295             <!-- Modal container for file management is defined globally below -->
    296 
    297             <?php
    298             // Check if additional response modal actions are available
    299             if (has_action('wpiko_chatbot_responses_scan_website_modal')): ?>
    300                 <?php do_action('wpiko_chatbot_responses_scan_website_modal'); ?>
    301                 <?php do_action('wpiko_chatbot_responses_qa_builder_modal'); ?>
    302                 <?php do_action('wpiko_chatbot_responses_woocommerce_integration_modal'); ?>
    303             <?php endif; ?>
    304         </div>
    305     </div>
    306 
    307 
    308         <input type="hidden" name="action" value="save_ai_configuration">
     340
     341            <input type="hidden" name="action" value="save_ai_configuration">
    309342        </form>
    310343
     
    320353    </div>
    321354    <?php
    322    
     355
    323356}
  • wpiko-chatbot/trunk/includes/responses-api.php

    r3406566 r3421683  
    3030        'gpt-5-mini',
    3131        'gpt-5-nano',
     32        // GPT-5.1 family
     33        'gpt-5.1',
     34        'gpt-5.1-chat-latest',
     35        // GPT-5.2 family
     36        'gpt-5.2',
     37        'gpt-5.2-chat-latest',
    3238        // o-series models
    3339        'o1-preview',
     
    4046    }
    4147    // Heuristic: most modern 4o/4.1/o-series variants support tools
    42     if (preg_match('/^(gpt-4o|gpt-4\.1|gpt-4-turbo|gpt-5|o[1-4]-mini|o[1-4]-preview)/', $model)) {
     48    if (preg_match('/^(gpt-4o|gpt-4\.1|gpt-4-turbo|gpt-5|gpt-5\.1|gpt-5\.2|o[1-4]-mini|o[1-4]-preview)/', $model)) {
    4349        return true;
    4450    }
     
    7682        function wpiko_chatbot_get_responses_api_models()
    7783        {
    78             return array('gpt-4.1' => 'GPT-4.1', 'gpt-4.1-mini' => 'GPT-4.1 Mini', 'gpt-4.1-nano' => 'GPT-4.1 Nano', 'gpt-5' => 'GPT-5', 'gpt-5-mini' => 'GPT-5 Mini', 'gpt-5-nano' => 'GPT-5 Nano');
     84            return array('gpt-4.1' => 'GPT-4.1', 'gpt-4.1-mini' => 'GPT-4.1 Mini', 'gpt-4.1-nano' => 'GPT-4.1 Nano', 'gpt-5' => 'GPT-5', 'gpt-5-mini' => 'GPT-5 Mini', 'gpt-5-nano' => 'GPT-5 Nano', 'gpt-5.1' => 'GPT-5.1', 'gpt-5.1-chat-latest' => 'GPT-5.1 Chat', 'gpt-5.2' => 'GPT-5.2', 'gpt-5.2-chat-latest' => 'GPT-5.2 Chat');
    7985        }
    8086    }
     
    485491        'gpt-5' => 'GPT-5',
    486492        'gpt-5-mini' => 'GPT-5 Mini',
    487         'gpt-5-nano' => 'GPT-5 Nano'
     493        'gpt-5-nano' => 'GPT-5 Nano',
     494        'gpt-5.1' => 'GPT-5.1',
     495        'gpt-5.1-chat-latest' => 'GPT-5.1 Chat',
     496        'gpt-5.2' => 'GPT-5.2',
     497        'gpt-5.2-chat-latest' => 'GPT-5.2 Chat'
    488498    );
    489499}
     
    550560    if (!$model || !is_string($model))
    551561        return false;
    552     $fixed = array('gpt-5', 'gpt-5-mini', 'gpt-5-nano');
     562    $fixed = array('gpt-5', 'gpt-5-mini', 'gpt-5-nano', 'gpt-5.1', 'gpt-5.1-chat-latest', 'gpt-5.2', 'gpt-5.2-chat-latest');
    553563    if (in_array($model, $fixed, true))
    554564        return true;
    555     return (bool) preg_match('/^gpt-5($|[-_])/', $model);
     565    return (bool) preg_match('/^gpt-5(\.\d+)?($|[-_])/', $model);
    556566}
    557567
  • wpiko-chatbot/trunk/readme.txt

    r3406566 r3421683  
    33Tags: chatbot, chatgpt, openai, woocommerce, live-chat
    44Requires at least: 6.0
    5 Tested up to: 6.8
    6 Stable tag: 1.0.6
     5Tested up to: 6.9
     6Stable tag: 1.0.7
    77Requires PHP: 7.0
    88License: GPL-2.0+
     
    114114== Changelog ==
    115115
     116= 1.0.7 =
     117* Added support for latest OpenAI models: GPT-5.1, GPT-5.1 Chat, GPT-5.2, and GPT-5.2 Chat
     118* Added model information display with accurate specifications for all new models
     119
    116120= 1.0.6 =
    117121* Added client-side timeout handling (90s for chatbot, 60s for contact form) - users now receive clear feedback instead of waiting indefinitely
  • wpiko-chatbot/trunk/wpiko-chatbot.php

    r3406566 r3421683  
    44 * Plugin URI: https://wpiko.com/chatbot
    55 * Description: A WordPress plugin that integrates OpenAI's AI models to create an intelligent chatbot for WordPress websites.
    6  * Version: 1.0.6
     6 * Version: 1.0.7
    77 * Author: WPiko
    88 * Author URI: https://wpiko.com
     
    2020define('WPIKO_CHATBOT_PLUGIN_DIR', plugin_dir_path(__FILE__));
    2121define('WPIKO_CHATBOT_PLUGIN_URL', plugin_dir_url(__FILE__));
    22 define('WPIKO_CHATBOT_VERSION', '1.0.6');
     22define('WPIKO_CHATBOT_VERSION', '1.0.7');
    2323
    2424// Ensures that the default options is set
    25 function wpiko_chatbot_set_default_options() {
     25function wpiko_chatbot_set_default_options()
     26{
    2627    $default_image = WPIKO_CHATBOT_PLUGIN_URL . 'assets/images/chatbot-icon.png';
    2728    add_option('wpiko_chatbot_image', $default_image);
    2829    add_option('wpiko_chatbot_floating_position', 'right');
    29    
     30
    3031    // Set default to Responses API for new installations
    3132    add_option('wpiko_chatbot_api_type', 'responses');
     
    4142
    4243// Enqueuing the necessary scripts and files
    43 function wpiko_chatbot_enqueue_scripts() {
     44function wpiko_chatbot_enqueue_scripts()
     45{
    4446    // Use defined version constant with dynamic cache-busting
    4547    $version = WPIKO_CHATBOT_VERSION;
    4648    $version = apply_filters('wpiko_chatbot_asset_version', $version);
    47    
     49
    4850    wp_enqueue_script('wpiko-chatbot-js', WPIKO_CHATBOT_PLUGIN_URL . 'js/wpiko-chatbot.js', array('jquery'), $version, true);
    4951    wp_enqueue_style('wpiko-chatbot-css', WPIKO_CHATBOT_PLUGIN_URL . 'css/wpiko-chatbot.css', array(), $version);
    50    
     52
    5153    // Read CSS content for inlining in transcript downloads
    5254    $css_path = WPIKO_CHATBOT_PLUGIN_DIR . 'css/frontend-transcript-styles.css';
     
    5557        $css_content = file_get_contents($css_path);
    5658    }
    57    
     59
    5860    // Localize script for frontend transcript CSS
    5961    wp_localize_script('wpiko-chatbot-js', 'wpikoAjax', array(
     
    6567
    6668// Include files
    67    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/admin-page.php';
    68    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/includes/plugin-header.php';
    69    
    70    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/dashboard-section.php';
    71    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/api-key-section.php';
    72    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/ai-configuration-section.php';
    73    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/floating-chatbot-section.php';
    74    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/shortcode-chatbot-section.php';
    75    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/chatbot-style-section.php';
    76    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/chatbot-menu-section.php';
    77    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/questions-section.php';
    78    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/conversations-section.php';
    79    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/error-messages-section.php';
    80    
    81    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'chatbot-interface.php';
    82    
    83    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/logging.php'; 
    84    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/floating-chatbot.php';
    85    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/responses-api.php';
    86    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/conversation-handler.php';
    87    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/markdown-handler.php';
    88    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/api-helpers.php';
    89    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/sound-functions.php';
    90    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/files-list-handler.php';
    91    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/instructions-handler.php';
    92    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/cache-management.php';
    93    require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/conversation-translation.php';
     69require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/admin-page.php';
     70require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/includes/plugin-header.php';
     71
     72require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/dashboard-section.php';
     73require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/api-key-section.php';
     74require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/ai-configuration-section.php';
     75require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/floating-chatbot-section.php';
     76require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/shortcode-chatbot-section.php';
     77require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/chatbot-style-section.php';
     78require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/chatbot-menu-section.php';
     79require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/questions-section.php';
     80require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/conversations-section.php';
     81require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/error-messages-section.php';
     82
     83require_once WPIKO_CHATBOT_PLUGIN_DIR . 'chatbot-interface.php';
     84
     85require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/logging.php';
     86require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/floating-chatbot.php';
     87require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/responses-api.php';
     88require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/conversation-handler.php';
     89require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/markdown-handler.php';
     90require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/api-helpers.php';
     91require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/sound-functions.php';
     92require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/files-list-handler.php';
     93require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/instructions-handler.php';
     94require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/cache-management.php';
     95require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/conversation-translation.php';
    9496
    9597// Register shortcode
     
    9799
    98100// Shortcode function to display the chatbot
    99 function wpiko_chatbot_shortcode($atts) {
     101function wpiko_chatbot_shortcode($atts)
     102{
    100103    // Process any attributes if needed
    101104    $atts = shortcode_atts(array(
    102105        // You can add custom attributes here if needed
    103106    ), $atts);
    104    
     107
    105108    // Return the chatbot display
    106109    return wpiko_chatbot_display();
     
    108111
    109112// Add AJAX handler for sending messages
    110 function wpiko_chatbot_ajax_handler() {
     113function wpiko_chatbot_ajax_handler()
     114{
    111115    check_ajax_referer('wpiko_chatbot_nonce', 'security');
    112    
     116
    113117    $encrypted_api_key = get_option('wpiko_chatbot_api_key', '');
    114118    $api_key = wpiko_chatbot_decrypt_api_key($encrypted_api_key);
     
    130134        wp_die();
    131135    }
    132    
     136
    133137    $message = sanitize_textarea_field(wp_unslash($_POST['message']));
    134138    $conversation_id = isset($_POST['thread_id']) ? sanitize_text_field(wp_unslash($_POST['thread_id'])) : null;
    135139    $user_email = isset($_POST['user_email']) ? sanitize_email(wp_unslash($_POST['user_email'])) : '';
    136    
     140
    137141    // Process user_name parameter
    138142    if (isset($_POST['user_name'])) {
     
    142146        }
    143147    }
    144    
     148
    145149    if (is_user_logged_in()) {
    146150        $current_user = wp_get_current_user();
     
    149153
    150154    $result = wpiko_chatbot_responses_api_call($message, $conversation_id, $user_email);
    151    
     155
    152156    if (isset($result['success']) && $result['success'] === false) {
    153157        wp_send_json_error($result['data']);
     
    155159        // Debug logging
    156160        wpiko_chatbot_log('Responses API result: ' . json_encode($result), 'info');
    157        
     161
    158162        // Ensure response is a string
    159163        $response_text = isset($result['response']) ? $result['response'] : '';
     
    162166            $response_text = (string) $response_text;
    163167        }
    164        
     168
    165169        // Format response to match expected format
    166170        $response_data = array(
     
    170174        wp_send_json_success($response_data);
    171175    }
    172    
     176
    173177    wp_die();
    174178}
     
    178182
    179183
    180 function wpiko_chatbot_localize_script() {
     184function wpiko_chatbot_localize_script()
     185{
    181186    $encrypted_api_key = get_option('wpiko_chatbot_api_key', '');
    182187    $api_key = wpiko_chatbot_decrypt_api_key($encrypted_api_key);
    183188    $sound_enabled = get_option('wpiko_chatbot_sound_enabled', '1');
    184    
     189
    185190    // Configuration is complete if API key is set (using Responses API)
    186191    $config_complete = !empty($api_key);
    187    
     192
    188193    // Get reCAPTCHA settings
    189194    $enable_recaptcha = get_option('wpiko_chatbot_enable_recaptcha', '0');
     
    220225
    221226// Function to encrypt the API key
    222 function wpiko_chatbot_encrypt_api_key($api_key) {
    223     if (empty($api_key)) return '';
    224    
     227function wpiko_chatbot_encrypt_api_key($api_key)
     228{
     229    if (empty($api_key))
     230        return '';
     231
    225232    $encryption_key = wp_salt('auth');
    226233    $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('AES-256-CBC'));
    227234    $encrypted = openssl_encrypt($api_key, 'AES-256-CBC', $encryption_key, 0, $iv);
    228    
     235
    229236    return base64_encode($encrypted . '::' . $iv);
    230237}
    231238
    232239// Function to decrypt the API key
    233 function wpiko_chatbot_decrypt_api_key($encrypted_api_key) {
    234     if (empty($encrypted_api_key)) return '';
    235    
     240function wpiko_chatbot_decrypt_api_key($encrypted_api_key)
     241{
     242    if (empty($encrypted_api_key))
     243        return '';
     244
    236245    $encryption_key = wp_salt('auth');
    237246    list($encrypted_data, $iv) = explode('::', base64_decode($encrypted_api_key), 2);
    238    
     247
    239248    return openssl_decrypt($encrypted_data, 'AES-256-CBC', $encryption_key, 0, $iv);
    240249}
     
    245254 * @return bool Whether the pro plugin is active
    246255 */
    247 function wpiko_chatbot_is_pro_plugin_active() {
     256function wpiko_chatbot_is_pro_plugin_active()
     257{
    248258    if (!function_exists('is_plugin_active')) {
    249259        include_once ABSPATH . 'wp-admin/includes/plugin.php';
    250260    }
    251    
     261
    252262    return is_plugin_active('wpiko-chatbot-pro/wpiko-chatbot-pro.php');
    253263}
     
    256266 * Check if WooCommerce is active
    257267 */
    258 function wpiko_chatbot_is_woocommerce_active() {
     268function wpiko_chatbot_is_woocommerce_active()
     269{
    259270    if (!function_exists('is_plugin_active')) {
    260271        include_once ABSPATH . 'wp-admin/includes/plugin.php';
    261272    }
    262    
     273
    263274    return is_plugin_active('woocommerce/woocommerce.php');
    264275}
Note: See TracChangeset for help on using the changeset viewer.