Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ node_modules/
.agents/loop-state/

.aidevops.json

# Local-only smoke tests / dev scratch — never ship: contains personal
# paths, hardcoded admin passwords, and developer-host URLs.
/wp-*-test.mjs
/wp-*-test.js
2 changes: 1 addition & 1 deletion build/connector.js

Large diffs are not rendered by default.

52 changes: 33 additions & 19 deletions inc/provider-registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,52 @@

use WordPress\AiClient\AiClient;
use AnthropicMaxAiProvider\Authentication\AnthropicOAuthRequestAuthentication;
use AnthropicMaxAiProvider\Authentication\ChatGptCodexOAuthRequestAuthentication;
use AnthropicMaxAiProvider\OAuthPool\PoolManager;
use AnthropicMaxAiProvider\OAuthPool\PoolRegistry;
use AnthropicMaxAiProvider\Provider\AnthropicMaxProvider;
use AnthropicMaxAiProvider\Provider\ChatGptCodexProvider;

/**
* Registers the Anthropic Max provider with the AI Client on init.
* Registers all available OAuth-backed AI providers with the AI Client on init.
*
* Runs at priority 5 so the provider is available before most plugins
* act on `init` at the default priority of 10.
* Runs at priority 5 so providers are available before most plugins
* act on `init` at the default priority of 10. Each provider is only
* registered when its underlying account pool has at least one entry,
* so an empty pool leaves the WordPress AiClient registry untouched.
*/
function register_provider(): void {
if ( ! class_exists( AiClient::class ) ) {
return;
}

$pool = PoolManager::getInstance();

// Only register if there are accounts in the pool.
if ( $pool->count() === 0 ) {
return;
}

$registry = AiClient::defaultRegistry();

if ( $registry->hasProvider( AnthropicMaxProvider::class ) ) {
return;
// --- Anthropic Max (Claude via Max subscription OAuth) ---
$anthropic_pool = PoolManager::getInstance();
if ( $anthropic_pool->count() > 0
&& ! $registry->hasProvider( AnthropicMaxProvider::class )
) {
$registry->registerProvider( AnthropicMaxProvider::class );
$registry->setProviderRequestAuthentication(
AnthropicMaxProvider::class,
new AnthropicOAuthRequestAuthentication( $anthropic_pool )
);
}

$registry->registerProvider( AnthropicMaxProvider::class );

// Inject the OAuth authentication using the pool manager.
$registry->setProviderRequestAuthentication(
AnthropicMaxProvider::class,
new AnthropicOAuthRequestAuthentication( $pool )
);
// --- ChatGPT Codex (OpenAI ChatGPT Plus/Pro/Team OAuth → Codex backend) ---
// Distinct provider id (`ultimate-ai-connector-chatgpt-codex`) because
// the OAuth token is rejected by `api.openai.com` and only works
// against `chatgpt.com/backend-api/codex/responses`. See
// ChatGptCodexProvider class docblock for the live-test evidence.
$openai_pool = PoolRegistry::pool( 'openai' );
if ( $openai_pool->count() > 0
&& ! $registry->hasProvider( ChatGptCodexProvider::class )
) {
$registry->registerProvider( ChatGptCodexProvider::class );
$registry->setProviderRequestAuthentication(
ChatGptCodexProvider::class,
new ChatGptCodexOAuthRequestAuthentication( $openai_pool )
);
}
}
Loading