Changeset 62046
- Timestamp:
- 03/18/2026 05:50:06 PM (2 weeks ago)
- Location:
- trunk/src/wp-includes/php-ai-client/src
- Files:
-
- 5 edited
-
AiClient.php (modified) (1 diff)
-
Common/AbstractDataTransferObject.php (modified) (1 diff)
-
Providers/DTO/ProviderMetadata.php (modified) (2 diffs)
-
Tools/DTO/FunctionCall.php (modified) (1 diff)
-
Tools/DTO/FunctionResponse.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/php-ai-client/src/AiClient.php
r61942 r62046 85 85 * @var string The version of the AI Client. 86 86 */ 87 public const VERSION = '1.3. 0';87 public const VERSION = '1.3.1'; 88 88 /** 89 89 * @var ProviderRegistry|null The default provider registry instance. -
trunk/src/wp-includes/php-ai-client/src/Common/AbstractDataTransferObject.php
r61700 r62046 113 113 } 114 114 } 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 } 120 122 } 121 123 } -
trunk/src/wp-includes/php-ai-client/src/Providers/DTO/ProviderMetadata.php
r61942 r62046 5 5 6 6 use WordPress\AiClient\Common\AbstractDataTransferObject; 7 use WordPress\AiClient\Common\Exception\InvalidArgumentException; 7 8 use WordPress\AiClient\Providers\Enums\ProviderTypeEnum; 8 9 use WordPress\AiClient\Providers\Http\Enums\RequestAuthenticationMethod; … … 80 81 * @param string|null $description The provider's description. 81 82 * @param string|null $logoPath The full path to the provider's logo image file. 83 * @throws InvalidArgumentException If the provider ID contains invalid characters. 82 84 */ 83 85 public function __construct(string $id, string $name, ProviderTypeEnum $type, ?string $credentialsUrl = null, ?RequestAuthenticationMethod $authenticationMethod = null, ?string $description = null, ?string $logoPath = null) 84 86 { 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 } 85 94 $this->id = $id; 86 95 $this->name = $name; -
trunk/src/wp-includes/php-ai-client/src/Tools/DTO/FunctionCall.php
r61700 r62046 94 94 public static function getJsonSchema(): array 95 95 { 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]]]]; 97 97 } 98 98 /** -
trunk/src/wp-includes/php-ai-client/src/Tools/DTO/FunctionResponse.php
r61700 r62046 14 14 * @since 0.1.0 15 15 * 16 * @phpstan-type FunctionResponseArrayShape array{id : string, name: string, response: mixed}16 * @phpstan-type FunctionResponseArrayShape array{id?: string, name?: string, response: mixed} 17 17 * 18 18 * @extends AbstractDataTransferObject<FunctionResponseArrayShape> … … 24 24 public const KEY_RESPONSE = 'response'; 25 25 /** 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. 27 27 */ 28 private string $id;28 private ?string $id; 29 29 /** 30 * @var string The name of the function that was called.30 * @var string|null The name of the function that was called. 31 31 */ 32 private string $name;32 private ?string $name; 33 33 /** 34 34 * @var mixed The response data from the function. … … 40 40 * @since 0.1.0 41 41 * 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. 44 44 * @param mixed $response The response data from the function. 45 * @throws InvalidArgumentException If neither id nor name is provided. 45 46 */ 46 public function __construct( string $id,string $name, $response)47 public function __construct(?string $id, ?string $name, $response) 47 48 { 49 if ($id === null && $name === null) { 50 throw new InvalidArgumentException('At least one of id or name must be provided.'); 51 } 48 52 $this->id = $id; 49 53 $this->name = $name; … … 90 94 public static function getJsonSchema(): array 91 95 { 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]]]]; 93 97 } 94 98 /** … … 101 105 public function toArray(): array 102 106 { 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; 104 116 } 105 117 /** … … 111 123 { 112 124 static::validateFromArrayData($array, [self::KEY_RESPONSE]); 113 // Validate that at least one of id or name is provided114 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 }117 125 return new self($array[self::KEY_ID] ?? null, $array[self::KEY_NAME] ?? null, $array[self::KEY_RESPONSE]); 118 126 }
Note: See TracChangeset
for help on using the changeset viewer.