Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
485cd6a
feat: starts client adapter work
JasonTheAdams Aug 30, 2025
182e32a
Merge branch 'trunk' into http-adapter
JasonTheAdams Sep 2, 2025
51a5130
Merge branch 'trunk' into http-adapter
JasonTheAdams Sep 9, 2025
c06c468
refactor: rename file to use PSR-4 autoloading
JasonTheAdams Sep 9, 2025
845407a
chore: adds WordPress stubs to PHPStan
JasonTheAdams Sep 9, 2025
d0b9208
fix: corrects type issues
JasonTheAdams Sep 9, 2025
d7ef812
chore: cleans up phpstan file
JasonTheAdams Sep 9, 2025
f7ec38f
feat: adds nyholm/psr7 package for psr17 factory
JasonTheAdams Sep 9, 2025
8010654
feat: adds HTTPlug discovery strategy
JasonTheAdams Sep 9, 2025
4e0247f
feat: adds PSR17 discoverability
JasonTheAdams Sep 9, 2025
3998eb7
refactor: renames class
JasonTheAdams Sep 22, 2025
581de9e
refactor: removes stream args
JasonTheAdams Sep 22, 2025
5c66fde
feat: updates to PHP AI Client 0.2.0
JasonTheAdams Oct 21, 2025
4e80b89
feat: implements ClientWithOptionsInterface
JasonTheAdams Oct 21, 2025
de7de24
refactor: switches to using NetworkException
JasonTheAdams Oct 21, 2025
7943ed6
refactor: cleans up unnecessary conditions code
JasonTheAdams Nov 5, 2025
7c5d022
Merge branch 'trunk' into http-adapter
felixarntz Nov 7, 2025
990111a
Use consistent YAML formatting in PHPStan config.
felixarntz Nov 7, 2025
acd0e8b
Fix PHPStan errors after updates.
felixarntz Nov 7, 2025
a68e34c
Temp folder rename to fix incorrect casing.
felixarntz Nov 7, 2025
bf54101
Fix folder name.
felixarntz Nov 7, 2025
167aeb6
Fix PHP warning.
felixarntz Nov 7, 2025
c50d84b
Fix bug in HTTP client discovery implementation.
felixarntz Nov 7, 2025
a8aaf95
Wire up HTTP client discovery implementation.
felixarntz Nov 7, 2025
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
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"require": {
"php": ">=7.4",
"ext-json": "*",
"wordpress/php-ai-client": "^0.1"
"wordpress/php-ai-client": "^0.2",
"nyholm/psr7": "^1.5"
},
"require-dev": {
"automattic/vipwpcs": "^3.0",
Expand All @@ -39,7 +40,8 @@
"phpstan/phpstan": "~2.1",
"slevomat/coding-standard": "^8.0",
"squizlabs/php_codesniffer": "^3.7",
"wp-coding-standards/wpcs": "^3.0"
"wp-coding-standards/wpcs": "^3.0",
"szepeviktor/phpstan-wordpress": "^2.0"
},
"config": {
"allow-plugins": {
Expand All @@ -58,6 +60,6 @@
],
"phpcs": "phpcs",
"phpcbf": "phpcbf",
"phpstan": "phpstan analyze --memory-limit=256M"
"phpstan": "phpstan analyze --memory-limit=512M"
}
}
207 changes: 199 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 94 additions & 0 deletions includes/http/WP_AI_Client_Discovery_Strategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
/**
* WordPress AI Client Discovery Strategy
*
* @package WordPress\AI_Client
* @since n.e.x.t
*/

namespace WordPress\AI_Client\HTTP;

use Http\Discovery\Psr18ClientDiscovery;
use Http\Discovery\Strategy\DiscoveryStrategy;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Http\Client\ClientInterface;

/**
* Discovery strategy for WordPress HTTP client.
*
* @since n.e.x.t
*/
class WP_AI_Client_Discovery_Strategy implements DiscoveryStrategy {

/**
* Initialize and register the discovery strategy.
*
* @since n.e.x.t
* @return void
*/
public static function init() {
// Check if discovery is available.
if ( ! class_exists( '\Http\Discovery\Psr18ClientDiscovery' ) ) {
return;
}

// Register our discovery strategy.
Psr18ClientDiscovery::prependStrategy( self::class );
}

/**
* Get candidates for discovery.
*
* @param string $type The type of discovery.
*
* @return array<array<string, mixed>>
*/
public static function getCandidates( $type ) {
// PSR-18 HTTP Client.
if ( ClientInterface::class === $type ) {
return array(
array(
'class' => array( __CLASS__, 'createWordPressClient' ),
'condition' => array(
WordPress_HTTP_Client::class,
Psr17Factory::class,
),
),
);
}

// PSR-17 factories - Nyholm's Psr17Factory implements all of them.
$psr17_factories = array(
'Psr\Http\Message\RequestFactoryInterface',
'Psr\Http\Message\ResponseFactoryInterface',
'Psr\Http\Message\ServerRequestFactoryInterface',
'Psr\Http\Message\StreamFactoryInterface',
'Psr\Http\Message\UploadedFileFactoryInterface',
'Psr\Http\Message\UriFactoryInterface',
);

if ( in_array( $type, $psr17_factories, true ) ) {
return array(
array(
'class' => Psr17Factory::class,
'condition' => Psr17Factory::class,
),
);
}

return array();
}

/**
* Create an instance of the WordPress HTTP client.
*
* @return WordPress_HTTP_Client
*/
public static function createWordPressClient() {
$psr17_factory = new Psr17Factory();
return new WordPress_HTTP_Client(
$psr17_factory, // Response factory.
$psr17_factory // Stream factory.
);
}
}
Loading