v0.11.0 — OpenRouter model picker (AJAX refresh + cost preview + Phase-2 asset extract) Replaces the free-text slug inputs for analysis_model, writing_model, and editor_model with a smart picker fed by a daily-refreshed OpenRouter model registry. Picker shows context size + input/output price + provider, filters by per-field capability, previews per-generation cost using existing cost-tracker history, and keeps a custom-slug fallback. Daily registry refresh fires from inside on_daily_generation() before lock acquire — no new top-level cron event. Commit sequence (preserved for review): -353aa4efeat(models): OpenRouter model picker + AJAX refresh + cost preview -283fa55fix(phpcs): resolve 4 PHPCS violations in model-registry-refresh handler -1b1336astyle(phpcs): fix array syntax in model field + cost tracker -283f9f9style(phpcs): fix tabs vs spaces in settings-page.php -aa78591refactor(assets): extract model-picker refresh handler to generic-handle file Verification - PHPCS strict (CI scope): 0 errors / 0 warnings - PHPUnit: 206/206 (555 assertions, 2 pre-existing skips) - All new files under 300-line cap (field renderer 163, AJAX handler 82) - Security: AJAX nonce + manage_options cap; output escaped; input sanitized - Phase 2 ready: zero PRAUTOBLOGGER_* coupling in registry/picker/AJAX classes; generic asset handle peptiderepo-model-picker QA verdict: PASS (qa-reviews/prautoblogger/2026-04-23-aa78591.md) Out of scope (untouched): cto-review.yml, prautoblogger_image_model field (Workers AI FLUX, Phase 3), Peptide Search AI / Peptide News fields (Phase 2). Co-authored-by: Engineer PRAutoBlogger (in-session subagent) <engineer-prautoblogger@peptiderepo.users.noreply.github.com>
59 lines
1.7 KiB
JavaScript
59 lines
1.7 KiB
JavaScript
/**
|
|
* Model registry refresh handler for PRAutoBlogger admin settings.
|
|
*
|
|
* Handles the "Refresh Model List" button click in the AI Models admin tab.
|
|
* Sends AJAX request to refresh the OpenRouter model registry cache and shows
|
|
* success/error toast notifications.
|
|
*
|
|
* @see admin/class-admin-page.php — Renders the refresh button + nonce.
|
|
* @see ajax/class-model-registry-refresh.php — Server-side handler.
|
|
*/
|
|
(function ($) {
|
|
'use strict';
|
|
|
|
// Refresh model registry button.
|
|
$(document).on('click', '#prautoblogger-refresh-models', function (e) {
|
|
e.preventDefault();
|
|
var $btn = $(this);
|
|
var nonce = $btn.data('nonce');
|
|
var originalText = $btn.html();
|
|
|
|
$btn.prop('disabled', true).addClass('ab-btn-loading');
|
|
|
|
$.ajax({
|
|
url: ajaxurl,
|
|
method: 'POST',
|
|
data: {
|
|
action: 'prautoblogger_refresh_models',
|
|
nonce: nonce
|
|
},
|
|
timeout: 30000
|
|
})
|
|
.done(function (response) {
|
|
if (response.success && response.data && response.data.message) {
|
|
// Show success toast
|
|
var $notice = $('<div class="ab-save-notice" role="status"></div>')
|
|
.html('<span class="dashicons dashicons-yes"></span> ' + response.data.message)
|
|
.insertBefore('.ab-layout')
|
|
.delay(4000)
|
|
.fadeOut(function () {
|
|
$(this).remove();
|
|
});
|
|
}
|
|
})
|
|
.fail(function () {
|
|
var $notice = $('<div class="ab-save-notice notice-error" role="alert"></div>')
|
|
.html('<span class="dashicons dashicons-warning"></span> ' + 'Failed to refresh model list. Please try again.')
|
|
.insertBefore('.ab-layout')
|
|
.delay(5000)
|
|
.fadeOut(function () {
|
|
$(this).remove();
|
|
});
|
|
})
|
|
.always(function () {
|
|
$btn.prop('disabled', false).removeClass('ab-btn-loading').html(originalText);
|
|
});
|
|
});
|
|
|
|
})(jQuery);
|