Recent

ProviderclassPro only

Provider

Checks whether the WordPress AI Client can serve Ask the Docs requests.

The site owner configures providers under Settings > Connectors. This class never sees or stores API keys; it only asks the AI Client whether a configured model can handle the kind of prompt Ask the Docs sends.

Namespace: WebberZone\Knowledge_Base\Pro\AI
Since: 3.2.0
Source: includes/pro/ai/class-provider.php line 25

Methods

is_ai_client_supported() static

Whether the AI Client exists and AI is not disabled for this site.

Since: 3.2.0
Line: 99

static public function is_ai_client_supported(  ): bool;

Returns: bool — True if the AI Client can be used.

is_available()

Whether a configured provider supports the prompts Ask the Docs sends.

The result is cached because the check can query each provider’s model list.

Since: 3.2.0
Line: 117

public function is_available( bool $force = ... ): bool;
Type Name Description
bool $force Skip the cached result and check again.

Returns: bool — True if a suitable text generation model is available.

get_cached_status() static

The cached support check result, without running a new check.

Since: 3.2.0
Line: 143

static public function get_cached_status(  ): ?bool;

Returns: ?bool — True or false from the cache, or null when nothing is cached.

clear_cache() static

Clear the cached support check.

Since: 3.2.0
Line: 158

static public function clear_cache(  ): void;

Returns: void

get_request_timeout() static

Seconds each provider in the chain is given to answer before the next one is tried.

Some connectors enforce a longer minimum of their own, for example for reasoning models.

Since: 3.2.0
Line: 174

static public function get_request_timeout(  ): int;

Returns: int — Timeout in seconds.

get_request_budget() static

Longest time a question can spend with the providers, in seconds.

Covers the chosen and fallback providers plus a margin, and sizes the answer lock and the browser’s wait so neither gives up while a provider is still answering. Avoids looking up the chain, so it is safe to call before connectors are registered.

Since: 3.2.0
Line: 196

static public function get_request_budget(  ): int;

Returns: int — Budget in seconds.

get_model_options() static

Text generation models a provider offers.

Cached for a day, because listing them can query the provider.

Since: 3.2.0
Line: 210

static public function get_model_options( string $provider ): array;
Type Name Description
string $provider Provider ID.

Returns: array — string> Model names keyed by model ID. Empty when unknown.

get_selected_model() static

The model chosen in the settings for a provider in the chain.

Since: 3.2.0
Line: 255

static public function get_selected_model( string $provider ): string;
Type Name Description
string $provider Provider ID, or an empty string when WordPress chooses.

Returns: string — Model ID, or an empty string to use the provider’s default.

is_tripped() static

Whether a provider is paused after repeated errors.

Since: 3.2.0
Line: 295

static public function is_tripped( string $provider ): bool;
Type Name Description
string $provider Provider ID, or an empty string for automatic.

Returns: bool — Whether the provider is paused.

get_trip() static

The pause record for a provider.

Since: 3.2.0
Line: 307

static public function get_trip( string $provider ): ?array;
Type Name Description
string $provider Provider ID, or an empty string for automatic.

Returns: ?array — Pause record with until, failures, status, code and message, or null.

is_all_tripped() static

Whether every provider in the chain is paused.

Since: 3.2.0
Line: 320

static public function is_all_tripped(  ): bool;

Returns: bool — Whether all providers are paused.

get_error_status() static

The HTTP status behind a provider error, or 0 for a network failure.

Some connectors report the real status only in the message text, so a generic 500 is checked there before it is trusted.

Since: 3.2.0
Line: 341

static public function get_error_status( WP_Error $error ): int;
Type Name Description
\WP_Error $error Provider error.

Returns: int — HTTP status, or 0 when the request never reached the provider.

get_cooldown() static

Pause length for a failure, doubling with each consecutive failure.

Since: 3.2.0
Line: 369

static public function get_cooldown( int $status, int $failures ): int;
Type Name Description
int $status HTTP status of the error, or 0 for a network failure.
int $failures Consecutive failure count.

Returns: int — Cooldown in seconds.

record_failure() static

Record a provider error and pause the provider when it is worth pausing.

Network failures, rate limits, auth and quota errors, and server errors pause the provider; client errors like a bad request do not.

Since: 3.2.0
Line: 388

static public function record_failure( string $provider, WP_Error $error ): void;
Type Name Description
string $provider Provider ID, or an empty string for automatic.
\WP_Error $error Provider error.

Returns: void

record_success() static

Clear a provider’s pause and failure count after a successful request.

Since: 3.2.0
Line: 432

static public function record_success( string $provider ): void;
Type Name Description
string $provider Provider ID, or an empty string for automatic.

Returns: void

clear_trips() static

Clear every provider’s pause and failure count.

Since: 3.2.0
Line: 442

static public function clear_trips(  ): void;

Returns: void

create_builder() static

Create a prompt builder configured the way Ask the Docs uses it.

The AI Client’s support check takes the system instruction and JSON output settings into account, so the detection check and real requests must share this configuration.

Since: 3.2.0
Line: 465

static public function create_builder( string $prompt, string $system_instruction, ?string $provider = ..., ?string $model = ... ): \WP_AI_Client_Prompt_Builder|null;
Type Name Description
string $prompt User prompt text.
string $system_instruction System instruction.
string|null $provider Provider ID, an empty string to let WordPress choose,
string|null $model Model ID, an empty string for the provider’s default, or null

Returns: \WP_AI_Client_Prompt_Builder|null — Builder, or null if the AI Client is unavailable.

get_provider_options() static

AI providers that can be chosen in the settings.

Lists the AI provider connectors whose provider is registered with the AI Client, without contacting any provider.

Since: 3.2.0
Line: 499

static public function get_provider_options(  ): array;

Returns: array — string> Provider names keyed by provider ID.

get_configured_providers() static

AI providers that have credentials configured.

A subset of get_provider_options(), kept to providers the AI Client reports as configured.

Since: 3.2.0
Line: 536

static public function get_configured_providers(  ): array;

Returns: array — string> Provider names keyed by provider ID.

get_selected_provider() static

The provider chosen in the settings, if it is still available.

Since: 3.2.0
Line: 570

static public function get_selected_provider(  ): string;

Returns: string — Provider ID, or an empty string to let WordPress choose.

get_fallback_provider() static

The fallback provider chosen in the settings, if it is still available.

Since: 3.2.0
Line: 587

static public function get_fallback_provider(  ): string;

Returns: string — Provider ID, or an empty string when there is no fallback.

get_provider_chain() static

Providers to try in order: the chosen provider, then the fallback.

An empty chain member means WordPress chooses. A provider without credentials is dropped only when another chain member is configured, so a chosen provider missing credentials still fails the support check rather than being skipped.

Since: 3.2.0
Line: 608

static public function get_provider_chain(  ): array;

Returns: array — Provider IDs in order; array( '' ) when nothing is chosen.

get_response_schema() static

JSON schema for the model’s answer.

Since: 3.2.0
Line: 637

static public function get_response_schema(  ): array;

Returns: array — JSON schema.