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:
@@ -42,6 +42,34 @@ class WP_Agentic_Writer_Memanto_Client
|
||||
*/
|
||||
private $health_cache = null;
|
||||
|
||||
/**
|
||||
* Circuit breaker transient key.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private const CIRCUIT_TRANSIENT = "wpaw_memanto_circuit";
|
||||
|
||||
/**
|
||||
* Circuit breaker timestamp transient key.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private const CIRCUIT_SINCE_TRANSIENT = "wpaw_memanto_circuit_since";
|
||||
|
||||
/**
|
||||
* Circuit breaker timeout in seconds (try again after this).
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private const CIRCUIT_TIMEOUT = 60;
|
||||
|
||||
/**
|
||||
* Circuit breaker max duration in seconds (stay open max this long).
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private const CIRCUIT_MAX_DURATION = 300;
|
||||
|
||||
/**
|
||||
* Get singleton instance.
|
||||
*
|
||||
@@ -56,14 +84,85 @@ class WP_Agentic_Writer_Memanto_Client
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Create a one-off client for a specific base URL.
|
||||
*
|
||||
* @param string $base_url MEMANTO base URL.
|
||||
* @return WP_Agentic_Writer_Memanto_Client
|
||||
*/
|
||||
private function __construct()
|
||||
public static function for_base_url($base_url)
|
||||
{
|
||||
return new self($base_url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string|null $base_url Optional MEMANTO base URL override.
|
||||
*/
|
||||
private function __construct($base_url = null)
|
||||
{
|
||||
if (null !== $base_url) {
|
||||
$this->base_url = untrailingslashit($base_url);
|
||||
return;
|
||||
}
|
||||
|
||||
$settings = get_option("wp_agentic_writer_settings", []);
|
||||
$this->base_url = untrailingslashit($settings["memanto_url"] ?? "");
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Circuit Breaker
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* Check if circuit breaker allows requests.
|
||||
*
|
||||
* @return bool True if circuit is closed (requests allowed), false if open (skip).
|
||||
*/
|
||||
private function check_circuit_breaker()
|
||||
{
|
||||
$state = get_transient(self::CIRCUIT_TRANSIENT);
|
||||
|
||||
if ($state !== "open") {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Circuit is open — check if timeout has passed.
|
||||
$since = get_transient(self::CIRCUIT_SINCE_TRANSIENT);
|
||||
|
||||
if ($since && time() - $since < self::CIRCUIT_TIMEOUT) {
|
||||
wpaw_debug_log("MEMANTO circuit breaker is open, skipping request");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Timeout passed — try again (half-open state).
|
||||
delete_transient(self::CIRCUIT_TRANSIENT);
|
||||
delete_transient(self::CIRCUIT_SINCE_TRANSIENT);
|
||||
wpaw_debug_log("MEMANTO circuit breaker resetting, attempting request");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trip the circuit breaker (open state).
|
||||
*
|
||||
* Once open, requests are skipped for CIRCUIT_TIMEOUT seconds,
|
||||
* then it retries. Max duration is CIRCUIT_MAX_DURATION.
|
||||
*/
|
||||
private function trip_circuit_breaker()
|
||||
{
|
||||
set_transient(
|
||||
self::CIRCUIT_TRANSIENT,
|
||||
"open",
|
||||
self::CIRCUIT_MAX_DURATION,
|
||||
);
|
||||
set_transient(
|
||||
self::CIRCUIT_SINCE_TRANSIENT,
|
||||
time(),
|
||||
self::CIRCUIT_MAX_DURATION,
|
||||
);
|
||||
wpaw_debug_log("MEMANTO circuit breaker tripped");
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Configuration & Health
|
||||
// =========================================================================
|
||||
@@ -98,6 +197,7 @@ class WP_Agentic_Writer_Memanto_Client
|
||||
{
|
||||
return $this->is_enabled() &&
|
||||
$this->is_configured() &&
|
||||
$this->check_circuit_breaker() &&
|
||||
$this->is_healthy();
|
||||
}
|
||||
|
||||
@@ -527,7 +627,11 @@ class WP_Agentic_Writer_Memanto_Client
|
||||
"timeout" => 10,
|
||||
]);
|
||||
|
||||
return $this->parse_response($response);
|
||||
$result = $this->parse_response($response);
|
||||
if (is_wp_error($result)) {
|
||||
$this->trip_circuit_breaker();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -575,7 +679,11 @@ class WP_Agentic_Writer_Memanto_Client
|
||||
}
|
||||
}
|
||||
|
||||
return $this->parse_response($response);
|
||||
$result = $this->parse_response($response);
|
||||
if (is_wp_error($result)) {
|
||||
$this->trip_circuit_breaker();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user