Skip to content

Commit e3d2cbf

Browse files
committed
Merge branch 'trunk' into explore/alternative-agents
2 parents 0ce300d + f9acb52 commit e3d2cbf

File tree

55 files changed

+800
-183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+800
-183
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ vendor/
2525
############
2626

2727
.claude/
28-
CLAUDE.md
28+
.clinerules
2929
.clinerules/
30+
.codex/
3031
.cursor/
32+
.gemini/
33+
.windsurf/
34+
CLAUDE.md
3135
GEMINI.md
3236

3337
############

AGENTS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ For a more detailed overview, refer to the `docs/ARCHITECTURE.md` file.
6868

6969
## Agent Guidelines
7070

71+
### Naming conventions
72+
7173
### DO:
7274

7375
* **Read the Docs:** Before making any changes, thoroughly read `CONTRIBUTING.md` and `docs/ARCHITECTURE.md`.
@@ -83,6 +85,15 @@ For a more detailed overview, refer to the `docs/ARCHITECTURE.md` file.
8385
* **Introduce Out-of-Scope Features:** Do not add features that are out of scope for this project, such as agents or the Model Context Protocol (MCP), as noted in `docs/REQUIREMENTS.md`.
8486
* **Duplicate Documentation:** Avoid duplicating PHPDoc descriptions for methods that implement an interface.
8587

88+
### Exception handling
89+
90+
All exceptions must use the project's custom exception classes rather than PHP built-in exceptions. This includes:
91+
92+
- Use the custom primitive exceptions in `WordPress\AiClient\Common\Exception\` instead of the PHP primitive exceptions
93+
- If a PHP primitive exception is needed that doesn't have a custom exception counterpart, then create one that extends the primitive and implements AiClientExceptionInterface
94+
- All custom exceptions implement `WordPress\AiClient\Exceptions\AiClientExceptionInterface` for unified exception handling
95+
- Follow usage-driven design: only implement static factory methods that are actually used in the codebase
96+
8697
## Common Pitfalls
8798

8899
* **Direct HTTP Client Usage:** A common mistake is to instantiate a PSR-18 client directly in a model. This is incorrect. Instead, the model should receive an `HttpTransporter` instance and use it to send requests.

docs/REQUIREMENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ This document outlines the functional requirements for the PHP AI Client, as wel
44

55
## Target Audiences
66

7-
There are two primary developer audiences this client is intended for. This is important to understand as it significantly influences the thinking and complexity around the APIs introduced in this library.a
7+
There are two primary developer audiences this client is intended for. This is important to understand as it significantly influences the thinking and complexity around the APIs introduced in this library.
88

99
### Extenders
1010

1111
Extenders are the folks that will be adding providers, models, and otherwise extending the functionality of the client itself. These are highly technical people who likely have a stronger understanding of how models and model APIs work. Given their capabilities, these APIs will be more technical and formal in nature, using things such as interfaces, traits, and so forth, relying on a knowledge of inheritance and composition.
1212

1313
### Implementers
1414

15-
Implementors are the folks that will be utilizing the client to take advantage of AI features. These developers know their own codebase well, but their technical and model knowledge varies. It is important not to rely on this knowledge for them to get significant value from the client. The APIs for these people will be simpler, straightforward, readable, and composable, so they can interact with the model with only what they need to know in mind.
15+
Implementers are the folks that will be utilizing the client to take advantage of AI features. These developers know their own codebase well, but their technical and model knowledge varies. It is important not to rely on this knowledge for them to get significant value from the client. The APIs for these people will be simpler, straightforward, readable, and composable, so they can interact with the model with only what they need to know in mind.
1616

1717
## Objective
1818

src/AiClient.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace WordPress\AiClient;
66

77
use WordPress\AiClient\Builders\PromptBuilder;
8+
use WordPress\AiClient\Common\Exception\InvalidArgumentException;
9+
use WordPress\AiClient\Common\Exception\RuntimeException;
810
use WordPress\AiClient\ProviderImplementations\Anthropic\AnthropicProvider;
911
use WordPress\AiClient\ProviderImplementations\Google\GoogleProvider;
1012
use WordPress\AiClient\ProviderImplementations\OpenAi\OpenAiProvider;
@@ -312,7 +314,7 @@ public static function generateSpeechResult(
312314
*/
313315
public static function message(?string $text = null)
314316
{
315-
throw new \RuntimeException(
317+
throw new RuntimeException(
316318
'MessageBuilder is not yet available. This method depends on builder infrastructure. ' .
317319
'Use direct generation methods (generateTextResult, generateImageResult, etc.) for now.'
318320
);
@@ -332,7 +334,7 @@ private static function validateModelOrConfigParameter($modelOrConfig): void
332334
&& !$modelOrConfig instanceof ModelInterface
333335
&& !$modelOrConfig instanceof ModelConfig
334336
) {
335-
throw new \InvalidArgumentException(
337+
throw new InvalidArgumentException(
336338
'Parameter must be a ModelInterface instance (specific model), ' .
337339
'ModelConfig instance (for auto-discovery), or null (default auto-discovery). ' .
338340
sprintf('Received: %s', is_object($modelOrConfig) ? get_class($modelOrConfig) : gettype($modelOrConfig))

src/Builders/PromptBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace WordPress\AiClient\Builders;
66

7-
use InvalidArgumentException;
8-
use RuntimeException;
7+
use WordPress\AiClient\Common\Exception\InvalidArgumentException;
8+
use WordPress\AiClient\Common\Exception\RuntimeException;
99
use WordPress\AiClient\Files\DTO\File;
1010
use WordPress\AiClient\Files\Enums\FileTypeEnum;
1111
use WordPress\AiClient\Messages\DTO\Message;

src/Common/AbstractDataTransferObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace WordPress\AiClient\Common;
66

7-
use InvalidArgumentException;
87
use JsonSerializable;
98
use stdClass;
109
use WordPress\AiClient\Common\Contracts\WithArrayTransformationInterface;
1110
use WordPress\AiClient\Common\Contracts\WithJsonSchemaInterface;
11+
use WordPress\AiClient\Common\Exception\InvalidArgumentException;
1212

1313
/**
1414
* Abstract base class for all Data Value Objects in the AI Client.

src/Common/AbstractEnum.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
namespace WordPress\AiClient\Common;
66

77
use BadMethodCallException;
8-
use InvalidArgumentException;
98
use JsonSerializable;
109
use ReflectionClass;
11-
use RuntimeException;
10+
use WordPress\AiClient\Common\Exception\InvalidArgumentException;
11+
use WordPress\AiClient\Common\Exception\RuntimeException;
1212

1313
/**
1414
* Abstract base class for enum-like behavior in PHP 7.4.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Common\Contracts;
6+
7+
use Throwable;
8+
9+
/**
10+
* Base interface for all AI Client exceptions.
11+
*
12+
* This interface allows callers to catch all AI Client specific exceptions
13+
* with a single catch statement.
14+
*
15+
* @since n.e.x.t
16+
*/
17+
interface AiClientExceptionInterface extends Throwable
18+
{
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Common\Exception;
6+
7+
use WordPress\AiClient\Common\Contracts\AiClientExceptionInterface;
8+
9+
/**
10+
* Exception thrown when an invalid argument is provided.
11+
*
12+
* This extends PHP's built-in InvalidArgumentException while implementing
13+
* the AI Client exception interface for consistent catch handling.
14+
*
15+
* @since n.e.x.t
16+
*/
17+
class InvalidArgumentException extends \InvalidArgumentException implements AiClientExceptionInterface
18+
{
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Common\Exception;
6+
7+
use WordPress\AiClient\Common\Contracts\AiClientExceptionInterface;
8+
9+
/**
10+
* Exception thrown for runtime errors.
11+
*
12+
* This extends PHP's built-in RuntimeException while implementing
13+
* the AI Client exception interface for consistent catch handling.
14+
*
15+
* @since n.e.x.t
16+
*/
17+
class RuntimeException extends \RuntimeException implements AiClientExceptionInterface
18+
{
19+
}

0 commit comments

Comments
 (0)