optimize cleanup search query shop api extends
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user