fix(amazon-shopping): enforce rating filters in chat output
This commit is contained in:
@@ -44,8 +44,8 @@ function formatFilters(filters: ProductFilters): string {
|
||||
return parts.length > 0 ? parts.join(", ") : "none";
|
||||
}
|
||||
|
||||
function escapeCell(value: string): string {
|
||||
return value.replace(/\|/g, "\\|").replace(/\s+/g, " ").trim();
|
||||
function compactText(value: string): string {
|
||||
return value.replace(/\s+/g, " ").trim();
|
||||
}
|
||||
|
||||
function marker(passes: boolean | undefined, enabled: boolean): string {
|
||||
@@ -82,24 +82,18 @@ function deliveryCell(product: ProductSearchResult, filters: ProductFilters): st
|
||||
return `${display}${marker(passes, true)}`;
|
||||
}
|
||||
|
||||
function resultTable(products: ProductSearchResult[], filters: ProductFilters): string[] {
|
||||
const rows = [
|
||||
"| # | Product | Price | Rating | Reviews | Width | Prime | Delivery | Link |",
|
||||
"|---|---|---:|---:|---:|---:|---|---|---|",
|
||||
...products.map((product, index) => [
|
||||
String(index + 1),
|
||||
escapeCell(product.title),
|
||||
product.price?.display ?? "unknown",
|
||||
`${product.rating ?? "unknown"} stars`,
|
||||
product.reviewCount?.toLocaleString("en-US") ?? "unknown",
|
||||
widthCell(product, filters),
|
||||
primeCell(product, filters),
|
||||
escapeCell(deliveryCell(product, filters)),
|
||||
`[Amazon](${product.url})`
|
||||
].join(" | "))
|
||||
.map((row) => `| ${row} |`)
|
||||
];
|
||||
return rows;
|
||||
function resultBlocks(products: ProductSearchResult[], filters: ProductFilters): string[] {
|
||||
return products.flatMap((product, index) => [
|
||||
`${index + 1}. ${compactText(product.title)}`,
|
||||
`Price: ${product.price?.display ?? "unknown"}`,
|
||||
`Rating: ${product.rating ?? "unknown"} stars`,
|
||||
`Reviews: ${product.reviewCount?.toLocaleString("en-US") ?? "unknown"}`,
|
||||
`Width: ${widthCell(product, filters)}`,
|
||||
`Prime: ${primeCell(product, filters)}`,
|
||||
`Delivery: ${compactText(deliveryCell(product, filters))}`,
|
||||
`Link: ${product.url}`,
|
||||
""
|
||||
]);
|
||||
}
|
||||
|
||||
function metadataLines(products: ProductSearchResult[]): string[] {
|
||||
@@ -129,7 +123,7 @@ export function createMarkdownReport(response: SearchProductsResponse): string {
|
||||
"## Best Matches",
|
||||
"",
|
||||
response.results.length > 0 ? "" : "No products matched all requested filters.",
|
||||
...resultTable(response.results, response.filters),
|
||||
...resultBlocks(response.results, response.filters),
|
||||
"",
|
||||
...metadataLines(response.results)
|
||||
].filter((line) => line !== "");
|
||||
|
||||
Reference in New Issue
Block a user