add shopware store-api

This commit is contained in:
team 1
2026-04-09 12:00:34 +02:00
parent 0ef3b43b30
commit 1aee32f1d8
13 changed files with 992 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Agent;
use App\Commerce\Dto\ShopProductResult;
use App\Context\ContextService;
use App\Repository\SystemPromptRepository;
use DateTimeImmutable;
@@ -24,6 +25,7 @@ final readonly class PromptBuilder
* @param string $userId
* @param string $urlContent
* @param string[] $knowledgeChunks
* @param ShopProductResult[] $shopResults
* @param bool $fullContext
* @return string
*/
@@ -32,6 +34,7 @@ final readonly class PromptBuilder
string $userId,
string $urlContent,
array $knowledgeChunks,
array $shopResults = [],
?bool $fullContext = false,
): string
{
@@ -69,7 +72,59 @@ final readonly class PromptBuilder
}
// ------------------------------------------------------------
// 3) EXTERNAL KNOWLEDGE (SUPPORTING)
// 3) LIVE SHOP RESULTS (AUTHORITATIVE FOR PRODUCTS)
// ------------------------------------------------------------
$shopBlock = '';
if ($shopResults !== []) {
$lines = [];
foreach ($shopResults as $i => $product) {
if (!$product instanceof ShopProductResult) {
continue;
}
$n = $i + 1;
$parts = [
"[{$n}] " . $product->name,
];
if ($product->productNumber) {
$parts[] = "Product number: " . $product->productNumber;
}
if ($product->manufacturer) {
$parts[] = "Manufacturer: " . $product->manufacturer;
}
if ($product->price) {
$parts[] = "Price: " . $product->price;
}
if ($product->available !== null) {
$parts[] = "Available: " . ($product->available ? 'yes' : 'no');
}
foreach ($product->highlights as $highlight) {
$parts[] = "- " . $highlight;
}
if ($product->url) {
$parts[] = "URL: " . $product->url;
}
$lines[] = implode("\n", $parts);
}
if ($lines !== []) {
$shopBlock =
"LIVE SHOP RESULTS (authoritative for products):\n" .
implode("\n\n", $lines);
}
}
// ------------------------------------------------------------
// 4) EXTERNAL KNOWLEDGE (SUPPORTING)
// ------------------------------------------------------------
$knowledgeParts = [];
@@ -98,22 +153,23 @@ final readonly class PromptBuilder
}
// ------------------------------------------------------------
// 4) USER QUESTION
// 5) USER QUESTION
// ------------------------------------------------------------
$userBlock =
"USER QUESTION:\n" .
$prompt;
// ------------------------------------------------------------
// 5) FINAL PROMPT ASSEMBLY
// 6) FINAL PROMPT ASSEMBLY
// ------------------------------------------------------------
$blocks = array_filter([
$systemBlock,
$contextBlock,
$shopBlock,
$knowledgeBlock,
$userBlock,
]);
return implode("\n\n", $blocks);
}
}
}