p64
This commit is contained in:
@@ -142,6 +142,20 @@ final class ChatMessagesConfig
|
||||
return $this->string('sse.storage.write_failed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getFrontendMessages(): array
|
||||
{
|
||||
$messages = $this->value('frontend');
|
||||
|
||||
if (is_array($messages)) {
|
||||
return $messages;
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('RetrieX chat messages config key "frontend" must be an array.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
@@ -165,6 +179,14 @@ final class ChatMessagesConfig
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->requiredStringListPaths() as $path) {
|
||||
try {
|
||||
$this->stringList($path);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$errors[] = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => $errors === [] ? 'OK' : 'ERROR',
|
||||
'errors' => $errors,
|
||||
@@ -202,6 +224,43 @@ final class ChatMessagesConfig
|
||||
'sse.claim.missing',
|
||||
'sse.storage.directory_create_failed',
|
||||
'sse.storage.write_failed',
|
||||
'frontend.document.title',
|
||||
'frontend.ui.header_title',
|
||||
'frontend.ui.footer_disclaimer',
|
||||
'frontend.ui.buttons.clear',
|
||||
'frontend.ui.buttons.send',
|
||||
'frontend.ui.buttons.abort',
|
||||
'frontend.ui.options.aria_label',
|
||||
'frontend.ui.options.status_info',
|
||||
'frontend.ui.input.prompt_placeholder',
|
||||
'frontend.assistant.loader',
|
||||
'frontend.assistant.aborted',
|
||||
'frontend.assistant.history_cleared',
|
||||
'frontend.source_chips.live_shop_data',
|
||||
'frontend.run_meta.completed_title',
|
||||
'frontend.run_meta.interrupted_title',
|
||||
'frontend.run_meta.completed_status',
|
||||
'frontend.run_meta.interrupted_status',
|
||||
'frontend.run_meta.completed_empty_source',
|
||||
'frontend.run_meta.interrupted_empty_source',
|
||||
'frontend.run_meta.pending_source_marker',
|
||||
'frontend.stream.incomplete',
|
||||
'frontend.stream.job_not_found_retry',
|
||||
'frontend.stream.failed_retry',
|
||||
'frontend.stream.interrupted_retry',
|
||||
'frontend.stream.missing_retry',
|
||||
'frontend.stream.stale_retry',
|
||||
'frontend.stream.connection_interrupted_retry',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function requiredStringListPaths(): array
|
||||
{
|
||||
return [
|
||||
'frontend.guards.no_concrete_shop_response_markers',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -237,6 +296,34 @@ final class ChatMessagesConfig
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function stringList(string $path): array
|
||||
{
|
||||
$value = $this->value($path);
|
||||
|
||||
if (!is_array($value)) {
|
||||
throw new \InvalidArgumentException(sprintf('RetrieX chat messages config key "%s" must be a list of non-empty strings.', $path));
|
||||
}
|
||||
|
||||
$items = [];
|
||||
|
||||
foreach ($value as $item) {
|
||||
if (!is_string($item) || trim($item) === '') {
|
||||
throw new \InvalidArgumentException(sprintf('RetrieX chat messages config key "%s" must contain only non-empty strings.', $path));
|
||||
}
|
||||
|
||||
$items[] = $item;
|
||||
}
|
||||
|
||||
if ($items === []) {
|
||||
throw new \InvalidArgumentException(sprintf('RetrieX chat messages config key "%s" must not be empty.', $path));
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function string(string $path): string
|
||||
{
|
||||
$value = $this->value($path);
|
||||
|
||||
27
src/Controller/ChatMessagesController.php
Normal file
27
src/Controller/ChatMessagesController.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Config\ChatMessagesConfig;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
final readonly class ChatMessagesController
|
||||
{
|
||||
public function __construct(private ChatMessagesConfig $chatMessages)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/chat-messages/frontend', name: 'chat_messages_frontend', methods: ['GET'])]
|
||||
public function frontend(): JsonResponse
|
||||
{
|
||||
$response = new JsonResponse($this->chatMessages->getFrontendMessages());
|
||||
$response->headers->set('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0');
|
||||
$response->headers->set('Pragma', 'no-cache');
|
||||
$response->headers->set('Expires', '0');
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user