Skip to content

Commit 856bae7

Browse files
committed
AI: Update the PHP AI Client library to version 1.5.1
This maintenance release hardens file input handling and deserialization, adds explicit file constructors, and deprecates implicit local file loading through the File constructor. Local paths remain supported by the prompt and message builders without deprecation notices. The update also adds a provider hook for preparing function parameter schemas and excludes function annotations from OpenAI-compatible tool request payloads. Developed in #15142. Props alekv, aryanjasala, gziolo, jason_the_adams, jeffpaul, jorgefilipecosta, laurisaarni. Fixes #66400. git-svn-id: https://develop.svn.wordpress.org/trunk@65001 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 73e9215 commit 856bae7

12 files changed

Lines changed: 442 additions & 56 deletions

File tree

‎src/wp-includes/php-ai-client/src/AiClient.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class AiClient
9090
/**
9191
* @var string The version of the AI Client.
9292
*/
93-
public const VERSION = '1.5.0';
93+
public const VERSION = '1.5.1';
9494
/**
9595
* @var ProviderRegistry|null The default provider registry instance.
9696
*/

‎src/wp-includes/php-ai-client/src/Builders/MessageBuilder.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use InvalidArgumentException;
77
use WordPress\AiClient\Files\DTO\File;
8+
use WordPress\AiClient\Files\Util\FileInputUtil;
89
use WordPress\AiClient\Messages\DTO\Message;
910
use WordPress\AiClient\Messages\DTO\MessagePart;
1011
use WordPress\AiClient\Messages\Enums\MessageRoleEnum;
@@ -143,6 +144,9 @@ public function withText(string $text): self
143144
* - Data URI string (data:mime/type;base64,data)
144145
* - Local file path string
145146
*
147+
* Resolving a local file path reads from the filesystem. Only pass strings you control; for untrusted
148+
* input, construct a File via File::fromUrl(), File::fromDataUri() or File::fromBase64() instead.
149+
*
146150
* @since 0.2.0
147151
*
148152
* @param string|File $file The file to add.
@@ -152,7 +156,7 @@ public function withText(string $text): self
152156
*/
153157
public function withFile($file, ?string $mimeType = null): self
154158
{
155-
$file = $file instanceof File ? $file : new File($file, $mimeType);
159+
$file = $file instanceof File ? $file : FileInputUtil::fromString($file, $mimeType);
156160
$this->parts[] = new MessagePart($file);
157161
return $this;
158162
}

‎src/wp-includes/php-ai-client/src/Builders/PromptBuilder.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use WordPress\AiClient\Files\DTO\File;
1313
use WordPress\AiClient\Files\Enums\FileTypeEnum;
1414
use WordPress\AiClient\Files\Enums\MediaOrientationEnum;
15+
use WordPress\AiClient\Files\Util\FileInputUtil;
1516
use WordPress\AiClient\Messages\DTO\Message;
1617
use WordPress\AiClient\Messages\DTO\MessagePart;
1718
use WordPress\AiClient\Messages\DTO\UserMessage;
@@ -133,6 +134,9 @@ public function withText(string $text): self
133134
* - Data URI string (data:mime/type;base64,data)
134135
* - Local file path string
135136
*
137+
* Resolving a local file path reads from the filesystem. Only pass strings you control; for untrusted
138+
* input, construct a File via File::fromUrl(), File::fromDataUri() or File::fromBase64() instead.
139+
*
136140
* @since 0.1.0
137141
*
138142
* @param string|File $file The file (File object or string representation).
@@ -142,7 +146,7 @@ public function withText(string $text): self
142146
*/
143147
public function withFile($file, ?string $mimeType = null): self
144148
{
145-
$file = $file instanceof File ? $file : new File($file, $mimeType);
149+
$file = $file instanceof File ? $file : FileInputUtil::fromString($file, $mimeType);
146150
$part = new MessagePart($file);
147151
$this->appendPartToMessages($part);
148152
return $this;

‎src/wp-includes/php-ai-client/src/Common/AbstractDataTransferObject.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ protected static function validateFromArrayData(array $data, array $requiredKeys
5151
/**
5252
* {@inheritDoc}
5353
*
54+
* The default implementation attempts to construct the object. Subclasses whose fromArray() has side
55+
* effects, is expensive, or handles untrusted input should override this with a structural check.
56+
*
5457
* @since 0.1.0
5558
*/
5659
public static function isArrayShape(array $array): bool

0 commit comments

Comments
 (0)