Make WordPress Core

Changeset 62046


Ignore:
Timestamp:
03/18/2026 05:50:06 PM (2 weeks ago)
Author:
flixos90
Message:

AI: Update PHP AI Client package to 1.3.1.

This package update fixes two bugs related to parsing function calls and function responses.

See release: https://github.com/WordPress/php-ai-client/releases/tag/1.3.1

See #64591.

Location:
trunk/src/wp-includes/php-ai-client/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/php-ai-client/src/AiClient.php

    r61942 r62046  
    8585     * @var string The version of the AI Client.
    8686     */
    87     public const VERSION = '1.3.0';
     87    public const VERSION = '1.3.1';
    8888    /**
    8989     * @var ProviderRegistry|null The default provider registry instance.
  • trunk/src/wp-includes/php-ai-client/src/Common/AbstractDataTransferObject.php

    r61700 r62046  
    113113                }
    114114            }
    115             // Handle oneOf schemas - just use the first one
    116             if (isset($schema['oneOf']) && is_array($schema['oneOf'])) {
    117                 foreach ($schema['oneOf'] as $possibleSchema) {
    118                     if (is_array($possibleSchema)) {
    119                         return $this->convertEmptyArraysToObjects($data, $possibleSchema);
     115            // Handle oneOf/anyOf schemas - just use the first one
     116            foreach (['oneOf', 'anyOf'] as $keyword) {
     117                if (isset($schema[$keyword]) && is_array($schema[$keyword])) {
     118                    foreach ($schema[$keyword] as $possibleSchema) {
     119                        if (is_array($possibleSchema)) {
     120                            return $this->convertEmptyArraysToObjects($data, $possibleSchema);
     121                        }
    120122                    }
    121123                }
  • trunk/src/wp-includes/php-ai-client/src/Providers/DTO/ProviderMetadata.php

    r61942 r62046  
    55
    66use WordPress\AiClient\Common\AbstractDataTransferObject;
     7use WordPress\AiClient\Common\Exception\InvalidArgumentException;
    78use WordPress\AiClient\Providers\Enums\ProviderTypeEnum;
    89use WordPress\AiClient\Providers\Http\Enums\RequestAuthenticationMethod;
     
    8081     * @param string|null $description The provider's description.
    8182     * @param string|null $logoPath The full path to the provider's logo image file.
     83     * @throws InvalidArgumentException If the provider ID contains invalid characters.
    8284     */
    8385    public function __construct(string $id, string $name, ProviderTypeEnum $type, ?string $credentialsUrl = null, ?RequestAuthenticationMethod $authenticationMethod = null, ?string $description = null, ?string $logoPath = null)
    8486    {
     87        if (!preg_match('/^[a-z0-9\-_]+$/', $id)) {
     88            throw new InvalidArgumentException(sprintf(
     89                // phpcs:ignore Generic.Files.LineLength.TooLong
     90                'Invalid provider ID "%s". Only lowercase alphanumeric characters, hyphens, and underscores are allowed.',
     91                $id
     92            ));
     93        }
    8594        $this->id = $id;
    8695        $this->name = $name;
  • trunk/src/wp-includes/php-ai-client/src/Tools/DTO/FunctionCall.php

    r61700 r62046  
    9494    public static function getJsonSchema(): array
    9595    {
    96         return ['type' => 'object', 'properties' => [self::KEY_ID => ['type' => 'string', 'description' => 'Unique identifier for this function call.'], self::KEY_NAME => ['type' => 'string', 'description' => 'The name of the function to call.'], self::KEY_ARGS => ['type' => ['string', 'number', 'boolean', 'object', 'array', 'null'], 'description' => 'The arguments to pass to the function.']], 'oneOf' => [['required' => [self::KEY_ID]], ['required' => [self::KEY_NAME]]]];
     96        return ['type' => 'object', 'properties' => [self::KEY_ID => ['type' => 'string', 'description' => 'Unique identifier for this function call.'], self::KEY_NAME => ['type' => 'string', 'description' => 'The name of the function to call.'], self::KEY_ARGS => ['type' => ['string', 'number', 'boolean', 'object', 'array', 'null'], 'description' => 'The arguments to pass to the function.']], 'anyOf' => [['required' => [self::KEY_ID]], ['required' => [self::KEY_NAME]]]];
    9797    }
    9898    /**
  • trunk/src/wp-includes/php-ai-client/src/Tools/DTO/FunctionResponse.php

    r61700 r62046  
    1414 * @since 0.1.0
    1515 *
    16  * @phpstan-type FunctionResponseArrayShape array{id: string, name: string, response: mixed}
     16 * @phpstan-type FunctionResponseArrayShape array{id?: string, name?: string, response: mixed}
    1717 *
    1818 * @extends AbstractDataTransferObject<FunctionResponseArrayShape>
     
    2424    public const KEY_RESPONSE = 'response';
    2525    /**
    26      * @var string The ID of the function call this is responding to.
     26     * @var string|null The ID of the function call this is responding to.
    2727     */
    28     private string $id;
     28    private ?string $id;
    2929    /**
    30      * @var string The name of the function that was called.
     30     * @var string|null The name of the function that was called.
    3131     */
    32     private string $name;
     32    private ?string $name;
    3333    /**
    3434     * @var mixed The response data from the function.
     
    4040     * @since 0.1.0
    4141     *
    42      * @param string $id The ID of the function call this is responding to.
    43      * @param string $name The name of the function that was called.
     42     * @param string|null $id The ID of the function call this is responding to.
     43     * @param string|null $name The name of the function that was called.
    4444     * @param mixed $response The response data from the function.
     45     * @throws InvalidArgumentException If neither id nor name is provided.
    4546     */
    46     public function __construct(string $id, string $name, $response)
     47    public function __construct(?string $id, ?string $name, $response)
    4748    {
     49        if ($id === null && $name === null) {
     50            throw new InvalidArgumentException('At least one of id or name must be provided.');
     51        }
    4852        $this->id = $id;
    4953        $this->name = $name;
     
    9094    public static function getJsonSchema(): array
    9195    {
    92         return ['type' => 'object', 'properties' => [self::KEY_ID => ['type' => 'string', 'description' => 'The ID of the function call this is responding to.'], self::KEY_NAME => ['type' => 'string', 'description' => 'The name of the function that was called.'], self::KEY_RESPONSE => ['type' => ['string', 'number', 'boolean', 'object', 'array', 'null'], 'description' => 'The response data from the function.']], 'oneOf' => [['required' => [self::KEY_RESPONSE, self::KEY_ID]], ['required' => [self::KEY_RESPONSE, self::KEY_NAME]]]];
     96        return ['type' => 'object', 'properties' => [self::KEY_ID => ['type' => 'string', 'description' => 'The ID of the function call this is responding to.'], self::KEY_NAME => ['type' => 'string', 'description' => 'The name of the function that was called.'], self::KEY_RESPONSE => ['type' => ['string', 'number', 'boolean', 'object', 'array', 'null'], 'description' => 'The response data from the function.']], 'anyOf' => [['required' => [self::KEY_RESPONSE, self::KEY_ID]], ['required' => [self::KEY_RESPONSE, self::KEY_NAME]]]];
    9397    }
    9498    /**
     
    101105    public function toArray(): array
    102106    {
    103         return [self::KEY_ID => $this->id, self::KEY_NAME => $this->name, self::KEY_RESPONSE => $this->response];
     107        $data = [];
     108        if ($this->id !== null) {
     109            $data[self::KEY_ID] = $this->id;
     110        }
     111        if ($this->name !== null) {
     112            $data[self::KEY_NAME] = $this->name;
     113        }
     114        $data[self::KEY_RESPONSE] = $this->response;
     115        return $data;
    104116    }
    105117    /**
     
    111123    {
    112124        static::validateFromArrayData($array, [self::KEY_RESPONSE]);
    113         // Validate that at least one of id or name is provided
    114         if (!array_key_exists(self::KEY_ID, $array) && !array_key_exists(self::KEY_NAME, $array)) {
    115             throw new InvalidArgumentException('At least one of id or name must be provided.');
    116         }
    117125        return new self($array[self::KEY_ID] ?? null, $array[self::KEY_NAME] ?? null, $array[self::KEY_RESPONSE]);
    118126    }
Note: See TracChangeset for help on using the changeset viewer.