optimize cleanup search query shop api extends

This commit is contained in:
team2
2026-04-25 22:05:35 +02:00
parent 4823752b3e
commit 6cf8aac872
4 changed files with 327 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Controller;
use App\Agent\AgentRunner;
use App\Context\ContextService;
use App\Http\ClientIdResolver;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
@@ -19,6 +20,7 @@ final readonly class AskSseController
public function __construct(
private AgentRunner $agentRunner,
private ClientIdResolver $clientIdResolver,
private ContextService $contextService,
private string $projectDir,
) {
}
@@ -166,15 +168,39 @@ final readonly class AskSseController
$this->sendData($chunk);
}
} catch (\Throwable $e) {
$message = 'Stream abgebrochen: ' . $this->formatThrowableForClient($e);
$this->sendEvent(
'error',
'❌ Stream abgebrochen: ' . $this->formatThrowableForClient($e)
'❌ ' . $message
);
if ($prompt !== '' && $clientId !== '') {
$this->appendHistoryFailure($clientId, $prompt, $message);
}
}
$this->sendEvent('done', '[DONE]');
}
private function appendHistoryFailure(string $clientId, string $prompt, string $message): void
{
try {
$message = trim(preg_replace('/\s+/u', ' ', $message) ?? $message);
if ($message === '') {
$message = 'Unbekannter Streamfehler.';
}
$this->contextService->appendHistory(
$clientId,
$prompt,
'Systemhinweis: Antwort konnte nicht abgeschlossen werden. Ursache: ' . $message
);
} catch (\Throwable) {
// History persistence must never break the SSE error response.
}
}
private function registerStreamShutdownErrorHandler(): void
{
register_shutdown_function(function (): void {