feat: interactive model picker with searchable popup and pricing

Replace plain text inputs for analysis/writing/editor model fields
with a rich model picker that fetches the OpenRouter model registry
and displays a searchable popup with model name, provider, input/output
pricing per 1M tokens, and context window. Also extracts source status
and model field renderers into dedicated field classes to keep
class-admin-page.php under the 300-line cap.

New files:
- assets/js/model-picker.js — popup UI with search, filtering, caching
- assets/css/model-picker.css — popup styles matching admin design system
- includes/admin/fields/class-open-router-model-field.php — server render
- includes/admin/fields/class-source-status-field.php — extracted field

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
peptiderepo
2026-04-18 02:53:40 +07:00
parent dcc8b7b183
commit 31f303a831
9 changed files with 670 additions and 51 deletions

View File

@@ -152,6 +152,34 @@ class PRAutoBlogger_Executor {
}
}
/**
* AJAX handler: return the model registry for the admin model picker.
*
* Returns the full cached model list. If the registry is empty, triggers
* a refresh first. Called by the model-picker.js popup.
*
* Side effects: may trigger an OpenRouter API call if registry is empty.
*/
public function on_ajax_get_models(): void {
check_ajax_referer( 'prautoblogger_get_models', 'nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( [ 'message' => __( 'Insufficient permissions.', 'prautoblogger' ) ], 403 );
return;
}
$registry = $this->get_model_registry();
$models = $registry->get_models();
// Auto-refresh if the registry has never been populated.
if ( empty( $models ) ) {
$registry->refresh( true );
$models = $registry->get_models();
}
wp_send_json_success( $models );
}
/** AJAX handler: test API connections (OpenRouter, Reddit). */
public function on_ajax_test_connection(): void {
check_ajax_referer( 'prautoblogger_test_connection', 'nonce' );