add shop result counter into response
This commit is contained in:
@@ -53,6 +53,8 @@ final readonly class AgentRunner
|
||||
$sources = [];
|
||||
$optimizedShopQuery = '';
|
||||
$shopSearchQuery = '';
|
||||
$shopSearchDisplayQuery = '';
|
||||
$shopSearchUsedOptimizedQuery = false;
|
||||
$commerceIntent = CommerceIntentLite::NONE;
|
||||
$knowledgeRetrievalPrompt = $prompt;
|
||||
$usedFollowUpRetrievalContext = false;
|
||||
@@ -127,7 +129,6 @@ final readonly class AgentRunner
|
||||
commerceHistoryContext: $commerceHistoryContext,
|
||||
userId: $userId
|
||||
);
|
||||
$usedResolvedOptimizedShopQuery = $optimizedShopQuery !== '' && $shopSearchQuery === $optimizedShopQuery;
|
||||
|
||||
if ($shopSearchQuery === '') {
|
||||
$this->agentLogger->info('Commerce search skipped because no concrete shop query could be resolved', [
|
||||
@@ -154,11 +155,16 @@ final readonly class AgentRunner
|
||||
$commerceHistoryContext
|
||||
);
|
||||
|
||||
$shopSearchDisplayQuery = $shopQueryPreview->searchText !== ''
|
||||
? $shopQueryPreview->searchText
|
||||
: $shopSearchQuery;
|
||||
$shopSearchUsedOptimizedQuery = $optimizedShopQuery !== '';
|
||||
|
||||
yield $this->systemMsg(
|
||||
$this->buildShopSearchMetaMessage(
|
||||
query: $shopQueryPreview->searchText !== '' ? $shopQueryPreview->searchText : $shopSearchQuery,
|
||||
query: $shopSearchDisplayQuery,
|
||||
commerceIntent: $commerceIntent,
|
||||
usedOptimizedQuery: $usedResolvedOptimizedShopQuery,
|
||||
usedOptimizedQuery: $shopSearchUsedOptimizedQuery,
|
||||
originalQuery: $shopSearchQuery
|
||||
),
|
||||
'meta'
|
||||
@@ -167,7 +173,7 @@ final readonly class AgentRunner
|
||||
$this->agentLogger->info('Commerce search prepared', [
|
||||
'userId' => $userId,
|
||||
'commerceIntent' => $commerceIntent,
|
||||
'usedOptimizedShopQuery' => $usedResolvedOptimizedShopQuery,
|
||||
'usedOptimizedShopQuery' => $optimizedShopQuery !== '',
|
||||
'optimizedShopQuery' => $optimizedShopQuery,
|
||||
'shopSearchQuery' => $shopSearchQuery,
|
||||
'hasCommerceHistoryContext' => $commerceHistoryContext !== '',
|
||||
@@ -232,6 +238,22 @@ final readonly class AgentRunner
|
||||
$usedShopRepair = $repairPayload['usedRepair'];
|
||||
$shopRepairQueries = $repairPayload['repairQueries'];
|
||||
|
||||
if ($shopSearchQuery !== '' && !$primaryShopSearchHadSystemFailure) {
|
||||
yield $this->systemMsg(
|
||||
$this->buildShopSearchMetaMessage(
|
||||
query: $shopSearchDisplayQuery !== '' ? $shopSearchDisplayQuery : $shopSearchQuery,
|
||||
commerceIntent: $commerceIntent,
|
||||
usedOptimizedQuery: $shopSearchUsedOptimizedQuery,
|
||||
originalQuery: $shopSearchQuery,
|
||||
resultCount: count($shopResults),
|
||||
completed: true,
|
||||
attemptedRepair: $attemptedShopRepair,
|
||||
usedRepair: $usedShopRepair
|
||||
),
|
||||
'meta'
|
||||
);
|
||||
}
|
||||
|
||||
if ($shopResults !== []) {
|
||||
$this->addSource($sources, $this->agentRunnerConfig->getShopSystemSourceLabel());
|
||||
}
|
||||
@@ -483,7 +505,7 @@ final readonly class AgentRunner
|
||||
return [];
|
||||
}
|
||||
|
||||
if (preg_match_all('/^Question:\s*(.+)$/mi', $history, $matches) < 1) {
|
||||
if (preg_match_all('/^Question:\s*(.+)$/mi', $history, $matches) !== 1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -724,20 +746,11 @@ final readonly class AgentRunner
|
||||
string $commerceHistoryContext,
|
||||
string $userId
|
||||
): string {
|
||||
$promptIsMetaOnly = $this->isMetaOnlyShopQuery($prompt);
|
||||
|
||||
/**
|
||||
* A pure meta command such as "suche im shop" has no own product
|
||||
* semantics. In that case the LLM optimizer must not be trusted as the
|
||||
* primary source because it can copy instruction terms from the query
|
||||
* prompt itself (for example "Shopware 6"). Resolve meta commands
|
||||
* deterministically from the recent conversation instead.
|
||||
*/
|
||||
if (!$promptIsMetaOnly && $optimizedShopQuery !== '' && !$this->isMetaOnlyShopQuery($optimizedShopQuery)) {
|
||||
if ($optimizedShopQuery !== '' && !$this->isMetaOnlyShopQuery($optimizedShopQuery)) {
|
||||
return $optimizedShopQuery;
|
||||
}
|
||||
|
||||
if (!$promptIsMetaOnly) {
|
||||
if (!$this->isMetaOnlyShopQuery($prompt)) {
|
||||
return $prompt;
|
||||
}
|
||||
|
||||
@@ -847,7 +860,7 @@ final readonly class AgentRunner
|
||||
$value = mb_strtolower(trim($value), 'UTF-8');
|
||||
$value = str_replace(['-', '/', '_'], ' ', $value);
|
||||
|
||||
if (preg_match_all('/\d+(?:[,.]\d+)?|[\p{L}\p{N}]+/u', $value, $matches) < 1) {
|
||||
if (preg_match_all('/\d+(?:[,.]\d+)?|[\p{L}\p{N}]+/u', $value, $matches) !== 1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -1294,7 +1307,11 @@ final readonly class AgentRunner
|
||||
string $query,
|
||||
string $commerceIntent,
|
||||
bool $usedOptimizedQuery,
|
||||
string $originalQuery
|
||||
string $originalQuery,
|
||||
?int $resultCount = null,
|
||||
bool $completed = false,
|
||||
bool $attemptedRepair = false,
|
||||
bool $usedRepair = false
|
||||
): string {
|
||||
$query = $this->normalizeOneLine($query);
|
||||
$originalQuery = $this->normalizeOneLine($originalQuery);
|
||||
@@ -1303,20 +1320,47 @@ final readonly class AgentRunner
|
||||
$query = $originalQuery !== '' ? $originalQuery : 'keine Suchquery ermittelt';
|
||||
}
|
||||
|
||||
$badge = $usedOptimizedQuery ? 'optimiert' : 'direkt';
|
||||
$queryModeLabel = $usedOptimizedQuery ? 'optimiert' : 'direkt';
|
||||
$intentLabel = $commerceIntent !== '' ? $commerceIntent : 'commerce';
|
||||
$title = $completed ? 'Shop-Suche abgeschlossen' : 'Shop-Suche wird ausgeführt';
|
||||
$statusLabel = $completed ? 'Status: abgeschlossen' : 'Status: läuft';
|
||||
$resultLabel = $resultCount === null
|
||||
? 'Shoptreffer: wird geladen'
|
||||
: 'Shoptreffer: ' . max(0, $resultCount);
|
||||
$state = $completed ? 'completed' : 'running';
|
||||
$resultCountAttribute = $resultCount === null ? '' : (string) max(0, $resultCount);
|
||||
$repairLabel = '';
|
||||
|
||||
return '<div class="retriex-meta-card retriex-shop-meta">'
|
||||
if ($usedRepair) {
|
||||
$repairLabel = 'Erweiterte Suche: genutzt';
|
||||
} elseif ($attemptedRepair) {
|
||||
$repairLabel = 'Erweiterte Suche: geprüft';
|
||||
}
|
||||
|
||||
$html = '<div class="retriex-meta-card retriex-shop-meta" data-retriex-meta-id="shop-search" data-retriex-meta-state="'
|
||||
. htmlspecialchars($state, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8')
|
||||
. '" data-retriex-shop-result-count="'
|
||||
. htmlspecialchars($resultCountAttribute, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8')
|
||||
. '">'
|
||||
. '<div class="retriex-meta-card__eyebrow">Live-Shopdaten</div>'
|
||||
. '<div class="retriex-meta-card__title">Shop-Suche wird ausgeführt</div>'
|
||||
. '<div class="retriex-meta-card__title">' . htmlspecialchars($title, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . '</div>'
|
||||
. '<div class="retriex-meta-card__body">'
|
||||
. '<span class="retriex-meta-pill">' . htmlspecialchars($badge, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . '</span>'
|
||||
. '<span class="retriex-meta-pill">Intent: ' . htmlspecialchars($intentLabel, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . '</span>'
|
||||
. '</div>'
|
||||
. '<span class="retriex-meta-pill retriex-meta-pill--result">' . htmlspecialchars($resultLabel, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . '</span>'
|
||||
. '<span class="retriex-meta-pill">' . htmlspecialchars($statusLabel, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . '</span>'
|
||||
. '<span class="retriex-meta-pill">Query: ' . htmlspecialchars($queryModeLabel, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . '</span>'
|
||||
. '<span class="retriex-meta-pill">Intent: ' . htmlspecialchars($intentLabel, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . '</span>';
|
||||
|
||||
if ($repairLabel !== '') {
|
||||
$html .= '<span class="retriex-meta-pill">' . htmlspecialchars($repairLabel, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . '</span>';
|
||||
}
|
||||
|
||||
$html .= '</div>'
|
||||
. '<div class="retriex-meta-query"><span>Gesendete Suchquery</span><code>'
|
||||
. htmlspecialchars($query, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8')
|
||||
. '</code></div>'
|
||||
. '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
private function buildShopUnavailableMessage(?string $reason): string
|
||||
|
||||
Reference in New Issue
Block a user