*/ protected array $input; /** * Optional metadata about the tool use. Clients SHOULD preserve this field when * including tool uses in subsequent sampling requests to enable caching optimizations. * * See [General fields: `_meta`](/specification/2025-11-25/basic/index#meta) for notes on `_meta` usage. * * @since 2025-11-25 * * @var array|null */ protected ?array $_meta; /** * @param string $id @since 2025-11-25 * @param string $name @since 2025-11-25 * @param array $input @since 2025-11-25 * @param array|null $_meta @since 2025-11-25 */ public function __construct( string $id, string $name, array $input, ?array $_meta = null ) { $this->type = self::TYPE; $this->id = $id; $this->name = $name; $this->input = $input; $this->_meta = $_meta; } /** * Creates an instance from an array. * * @param array{ * type: 'tool_use', * id: string, * name: string, * input: array, * _meta?: array|null * } $data * @phpstan-param array $data * @return self */ public static function fromArray(array $data): self { self::assertRequired($data, ['id', 'name', 'input']); return new self( self::asString($data['id']), self::asString($data['name']), self::asArray($data['input']), self::asArrayOrNull($data['_meta'] ?? null) ); } /** * Converts the instance to an array. * * @return array */ public function toArray(): array { $result = []; $result['type'] = $this->type; $result['id'] = $this->id; $result['name'] = $this->name; $result['input'] = $this->input; if ($this->_meta !== null) { $result['_meta'] = $this->_meta; } return $result; } /** * @return 'tool_use' */ public function getType(): string { return $this->type; } /** * @return string */ public function getId(): string { return $this->id; } /** * @return string */ public function getName(): string { return $this->name; } /** * @return array */ public function getInput(): array { return $this->input; } /** * @return array|null */ public function get_meta(): ?array { return $this->_meta; } }