diff --git a/composer.json b/composer.json index 9651b02..98892f9 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,7 @@ "test:lint": "@php vendor/bin/pint --config https://raw.githubusercontent.com/DIJ-digital/pint-config/main/pint.json", "test:unit": "pest", "test:types": "phpstan", - "test:refactor": "rector --dry-run", + "test:refactor": "rector", "test": [ "@test:lint", "@test:type-coverage", diff --git a/src/Health.php b/src/Health.php new file mode 100644 index 0000000..e396eeb --- /dev/null +++ b/src/Health.php @@ -0,0 +1,29 @@ +transporter->get( + uri: '/api/public/health', + ); + + /** @var array{status: string} $data */ + $data = json_decode($response->getBody()->getContents(), true, flags: JSON_THROW_ON_ERROR); + + return HealthResponse::fromArray($data); + } +} diff --git a/src/Langfuse.php b/src/Langfuse.php index ebe96f9..dded845 100644 --- a/src/Langfuse.php +++ b/src/Langfuse.php @@ -12,7 +12,13 @@ public function __construct( private readonly TransporterInterface $transporter, private readonly string $environment = 'default', private readonly string $label = 'latest', - ) { + ) {} + + public function health(): Health + { + return new Health( + transporter: $this->transporter, + ); } public function prompt(): Prompt diff --git a/src/Responses/HealthResponse.php b/src/Responses/HealthResponse.php new file mode 100644 index 0000000..713d4c5 --- /dev/null +++ b/src/Responses/HealthResponse.php @@ -0,0 +1,22 @@ +|string> $headers + * @param array $data + */ + public function __construct(int $status = 200, array $headers = [], string $version = '1.1', ?string $reason = null, array $data = []) + { + parent::__construct($status, $headers, (string) json_encode($this->payload($data)), $version, $reason); + } + + /** + * @param array $data + * @return array + */ + public function payload(array $data = []): array + { + return array_merge([ + 'status' => 'OK', + ], $data); + } +} diff --git a/tests/Feature/HealthTest.php b/tests/Feature/HealthTest.php new file mode 100644 index 0000000..8c0aae8 --- /dev/null +++ b/tests/Feature/HealthTest.php @@ -0,0 +1,24 @@ + $handlerStack]); + + $health = (new Langfuse(new HttpTransporter($client))) + ->health() + ->check(); + + expect($health)->toBeInstanceOf(HealthResponse::class) + ->and($health->status)->toBe('OK'); +});