refactor: Cleanup git state - commit all staged changes
Major refactoring cleanup: - Add new controller architecture (class-controller-*.php) - Add new settings-v2 UI (views/settings-v2/) - Add new CSS architecture (agentic-sidebar.css, tokens) - Add esbuild build pipeline (scripts/build.js, package.json) - Add composer dependencies (vendor/) - Add frontend src directory (assets/js/src/index.jsx) - Add documentation files - Remove old/obsolete files (class-settings.php, old CSS) This commits all pending changes from previous refactoring efforts.
This commit is contained in:
78
includes/class-controller-models.php
Normal file
78
includes/class-controller-models.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Models REST Controller
|
||||
*
|
||||
* Handles model listing and refresh operations.
|
||||
*
|
||||
* @package WP_Agentic_Writer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class WP_Agentic_Writer_Controller_Models
|
||||
*
|
||||
* REST controller for model operations.
|
||||
*
|
||||
* @since 0.3.0
|
||||
*/
|
||||
class WP_Agentic_Writer_Controller_Models {
|
||||
|
||||
/**
|
||||
* Sidebar instance for dependency access.
|
||||
*
|
||||
* @var WP_Agentic_Writer_Gutenberg_Sidebar
|
||||
*/
|
||||
private $sidebar;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 0.3.0
|
||||
* @param WP_Agentic_Writer_Gutenberg_Sidebar $sidebar Sidebar instance.
|
||||
*/
|
||||
public function __construct( $sidebar ) {
|
||||
$this->sidebar = $sidebar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle get models request.
|
||||
*
|
||||
* @since 0.1.0
|
||||
* @return WP_REST_Response|WP_Error Response.
|
||||
*/
|
||||
public function handle_get_models() {
|
||||
$provider = WP_Agentic_Writer_OpenRouter_Provider::get_instance();
|
||||
$models = $provider->get_cached_models();
|
||||
|
||||
if ( is_wp_error( $models ) ) {
|
||||
return $models;
|
||||
}
|
||||
|
||||
return new WP_REST_Response( $models, 200 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle refresh models request.
|
||||
*
|
||||
* @since 0.1.0
|
||||
* @return WP_REST_Response|WP_Error Response.
|
||||
*/
|
||||
public function handle_refresh_models() {
|
||||
$provider = WP_Agentic_Writer_OpenRouter_Provider::get_instance();
|
||||
$models = $provider->fetch_and_cache_models( true );
|
||||
|
||||
if ( is_wp_error( $models ) ) {
|
||||
return $models;
|
||||
}
|
||||
|
||||
return new WP_REST_Response(
|
||||
[
|
||||
'models' => $models,
|
||||
'message' => __(
|
||||
'Models refreshed successfully.',
|
||||
'wp-agentic-writer',
|
||||
),
|
||||
],
|
||||
200,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user