Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

feat(shopping): show what AI says about a product, quoted from the answers that showed it (Product Visibility, part 13) (#1648)

Cihana8bd335b61ff
diff --git a/web/messages/en.json b/web/messages/en.json
index 8262a8c1b..0a2ac7e1f 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -8188,6 +8188,16 @@
"lower": "{percent}% lower",
"firstWords": "ChatGPT reads about 40 words"
},
+ "says": {
+ "title": "What AI says",
+ "lead": "In the answers' own words: the last 30 days' {count, plural, one {# answer} other {# answers}} that showed it, and the sources they cited.",
+ "none": "No answer showed it in the last 30 days.",
+ "unnamed": "The answers showed it as a card, without naming it in their text.",
+ "asked": "“{prompt}”",
+ "sources": "Sources they cited",
+ "cited": "{count, plural, one {# answer} other {# answers}}",
+ "failed": "Couldn't read what AI says right now."
+ },
"actions": {
"title": "Actions to get on the shelf",
"lead": "Grouped by type. Choose who does each one, then send them to Action Center."
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/shopping/_ai-says.tsx b/web/src/app/[locale]/(dashboard)/dashboard/shopping/_ai-says.tsx
new file mode 100644
index 000000000..26386b111
--- /dev/null
+++ b/web/src/app/[locale]/(dashboard)/dashboard/shopping/_ai-says.tsx
@@ -0,0 +1,100 @@
+'use client';
+
+import { useTranslations } from 'next-intl';
+import { ExternalLink, Quote } from 'lucide-react';
+import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
+import { Skeleton } from '@/components/ui/skeleton';
+import { PLATFORM_LABELS } from '@/config/platform-labels';
+import { getFaviconUrl } from '@/lib/favicon';
+import { formatDate } from '@/lib/format';
+import type { ProductAiSays } from '@/lib/shopping/ai-says';
+
+/**
+ * "What AI says" on a product's page (ECOM-012, V1): quotes from the answers
+ * that showed it, and the sources they cited. `says`: undefined while it's
+ * read, null when it couldn't be.
+ */
+export function AiSaysCard({ says }: { says: ProductAiSays | null | undefined }) {
+ const t = useTranslations('shopping.detail.says');
+ return (
+ <Card>
+ <CardHeader className="pb-2">
+ <CardTitle className="text-base">{t('title')}</CardTitle>
+ {says && says.answers > 0 && (
+ <p className="text-sm text-muted-foreground">{t('lead', { count: says.answers })}</p>
+ )}
+ </CardHeader>
+ <CardContent className="space-y-4">
+ {says === undefined ? (
+ <Skeleton className="h-24 w-full" />
+ ) : says === null ? (
+ <p className="text-sm text-muted-foreground">{t('failed')}</p>
+ ) : says.answers === 0 ? (
+ <p className="text-sm text-muted-foreground">{t('none')}</p>
+ ) : (
+ <>
+ {says.quotes.length ? (
+ <ul className="space-y-3">
+ {says.quotes.map((quote) => (
+ <li key={quote.text} className="flex gap-2.5">
+ <Quote
+ className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground/60"
+ aria-hidden
+ />
+ <div className="min-w-0 space-y-0.5">
+ <p className="text-sm">{quote.text}</p>
+ <p className="truncate text-xs text-muted-foreground">
+ {[
+ PLATFORM_LABELS[quote.platform] ?? quote.platform,
+ quote.promptText ? t('asked', { prompt: quote.promptText }) : null,
+ formatDate(quote.at),
+ ]
+ .filter(Boolean)
+ .join(' · ')}
+ </p>
+ </div>
+ </li>
+ ))}
+ </ul>
+ ) : (
+ <p className="text-sm text-muted-foreground">{t('unnamed')}</p>
+ )}
+ {says.sources.length > 0 && (
+ <div className="space-y-1.5">
+ <p className="text-xs font-medium text-muted-foreground">{t('sources')}</p>
+ <ul className="space-y-1">
+ {says.sources.map((source) => (
+ <li key={source.url} className="flex min-w-0 items-center gap-2 text-sm">
+ {/* eslint-disable-next-line @next/next/no-img-element -- a source's favicon */}
+ <img
+ src={getFaviconUrl(source.domain, 32)}
+ alt=""
+ className="h-3.5 w-3.5 shrink-0 rounded-sm"
+ loading="lazy"
+ />
+ <a
+ href={source.url}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="inline-flex min-w-0 items-center gap-1 hover:underline"
+ >
+ <span className="truncate">{source.title || source.domain}</span>
+ <ExternalLink
+ className="h-3 w-3 shrink-0 text-muted-foreground"
+ aria-hidden
+ />
+ </a>
+ <span className="ml-auto shrink-0 text-xs tabular-nums text-muted-foreground">
+ {t('cited', { count: source.answers })}
+ </span>
+ </li>
+ ))}
+ </ul>
+ </div>
+ )}
+ </>
+ )}
+ </CardContent>
+ </Card>
+ );
+}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/shopping/_product-detail.tsx b/web/src/app/[locale]/(dashboard)/dashboard/shopping/_product-detail.tsx
index 1a4d03f73..aeeb0f5b0 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/shopping/_product-detail.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/shopping/_product-detail.tsx
@@ -15,6 +15,7 @@ import {
import { HeaderWithAiUsage } from '@/components/ai-usage/ai-usage-meter';
import { PLATFORM_LABELS } from '@/config/platform-labels';
import type { ShoppingProductDetail } from '@/lib/actions/shopping';
+import type { ProductAiSays } from '@/lib/shopping/ai-says';
import { formatNumber } from '@/lib/format';
import { priceText } from '@/lib/shopping/price';
import { READINESS_CHECKS } from '@/lib/shopping/products';
@@ -23,6 +24,7 @@ import { productPlan } from '@/lib/shopping/action-plan';
import { cn } from '@/lib/utils';
import { ActionPlan } from './_action-plan';
import { ActionResultCard } from './_action-result';
+import { AiSaysCard } from './_ai-says';
const platformName = (platform: string) => PLATFORM_LABELS[platform] ?? platform;
@@ -35,16 +37,20 @@ const STATE_ICON: Record<ComparisonState, React.ReactNode> = {
/**
* A product's page (ECOM-011), drawn: its header with its AI visits and
- * orders, "Why not your product?" beside the winner, its last done action
- * 7 days on (ECOM-018), where it shows, and its readiness.
+ * orders, "Why not your product?" beside the winner, what AI says about it
+ * (ECOM-012), its last done action 7 days on (ECOM-018), where it shows, and
+ * its readiness.
*/
export function ProductDetailView({
detail,
brandId,
+ aiSays,
}: {
detail: ShoppingProductDetail;
/** The brand, to send the actions with; none, no actions. */
brandId?: string;
+ /** What AI says, read after the rest: undefined while it's read, null when it couldn't be. */
+ aiSays?: ProductAiSays | null;
}) {
const t = useTranslations('shopping.detail');
const tReady = useTranslations('shopping.products.readiness');
@@ -174,6 +180,8 @@ export function ProductDetailView({
)}
</Card>
+ <AiSaysCard says={aiSays} />
+
{detail.result && <ActionResultCard result={detail.result} />}
{brandId && (
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/shopping/products/[productId]/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/shopping/products/[productId]/page.test.tsx
index 8594cfe83..6c6a5a507 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/shopping/products/[productId]/page.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/shopping/products/[productId]/page.test.tsx
@@ -8,8 +8,9 @@ import type { ShoppingProductDetail } from '@/lib/actions/shopping';
/** A product's page (ECOM-011). */
const getShoppingProductDetail = vi.hoisted(() => vi.fn());
+const getProductAiSays = vi.hoisted(() => vi.fn());
const gate = vi.hoisted(() => ({ allowed: true }));
-vi.mock('@/lib/actions/shopping', () => ({ getShoppingProductDetail }));
+vi.mock('@/lib/actions/shopping', () => ({ getShoppingProductDetail, getProductAiSays }));
// The query the page opens with: the Shelf's "Why not you?" names a shelf.
const query = vi.hoisted(() => ({ value: '' }));
vi.mock('next/navigation', () => ({
@@ -54,6 +55,7 @@ let root: Root;
beforeEach(() => {
gate.allowed = true;
getShoppingProductDetail.mockReset();
+ getProductAiSays.mockReset().mockResolvedValue({ answers: 0, quotes: [], sources: [] });
query.value = '';
container = document.createElement('div');
document.body.appendChild(container);
@@ -212,6 +214,53 @@ describe('ShoppingProductPage', () => {
expect(text).not.toContain('On more of its shelves');
});
+ it('quotes what AI says about it, with the sources the answers cited (ECOM-012)', async () => {
+ getShoppingProductDetail.mockResolvedValue(detail);
+ getProductAiSays.mockResolvedValue({
+ answers: 3,
+ quotes: [
+ {
+ text: 'The Ridge 30L Backpack is tougher, with a lifetime warranty.',
+ platform: 'chatgpt-shopping',
+ at: '2026-10-27T08:00:00Z',
+ promptText: 'best 30L hiking backpack',
+ },
+ ],
+ sources: [
+ {
+ url: 'https://outdoorgear.example/best',
+ domain: 'outdoorgear.example',
+ title: 'Best packs',
+ answers: 2,
+ },
+ ],
+ });
+ const text = await render();
+ expect(getProductAiSays).toHaveBeenCalledWith('b1', 'p1', { datePreset: '30d' });
+ expect(text).toContain('What AI says');
+ expect(text).toContain("the last 30 days' 3 answers that showed it");
+ expect(text).toContain('The Ridge 30L Backpack is tougher, with a lifetime warranty.');
+ expect(text).toContain('ChatGPT Shopping · “best 30L hiking backpack” · Oct 27, 2026');
+ expect(container.querySelector('a[href="https://outdoorgear.example/best"]')?.textContent).toBe(
+ 'Best packs',
+ );
+ expect(text).toContain('2 answers');
+ });
+
+ it('says when no answer showed it', async () => {
+ getShoppingProductDetail.mockResolvedValue(detail);
+ expect(await render()).toContain('No answer showed it in the last 30 days.');
+ });
+
+ it('keeps the page when what AI says could not be read', async () => {
+ getShoppingProductDetail.mockResolvedValue(detail);
+ getProductAiSays.mockRejectedValue(new Error('down'));
+ vi.spyOn(console, 'error').mockImplementation(() => {});
+ const text = await render();
+ expect(text).toContain('Ridge 30L Backpack');
+ expect(text).toContain("Couldn't read what AI says right now.");
+ });
+
it('says when the product is gone, or locked', async () => {
getShoppingProductDetail.mockResolvedValue(null);
expect(await render()).toContain("This product isn't in your catalog anymore.");
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/shopping/products/[productId]/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/shopping/products/[productId]/page.tsx
index 7087c1a05..7fd69b3d3 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/shopping/products/[productId]/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/shopping/products/[productId]/page.tsx
@@ -7,7 +7,12 @@ import { ArrowLeft } from 'lucide-react';
import { Link } from '@/i18n/navigation';
import { Skeleton } from '@/components/ui/skeleton';
import { useFeatureGate } from '@/hooks/use-feature-gate';
-import { getShoppingProductDetail, type ShoppingProductDetail } from '@/lib/actions/shopping';
+import {
+ getProductAiSays,
+ getShoppingProductDetail,
+ type ShoppingProductDetail,
+} from '@/lib/actions/shopping';
+import type { ProductAiSays } from '@/lib/shopping/ai-says';
import { useBrandStore } from '@/stores/use-brand-store';
import { ProductDetailView } from '../../_product-detail';
@@ -15,7 +20,9 @@ import { ProductDetailView } from '../../_product-detail';
* A product's page in Product Visibility (ECOM-011): where it stands on the
* AI shelves of the questions it belongs on, and "Why not your product?":
* it beside the product AI picked for the question it's missing most, row
- * by row, with its readiness and its AI visits and orders.
+ * by row, with its readiness and its AI visits and orders. What AI says
+ * about it (ECOM-012) is read apart, its card filled when it comes: the
+ * answers' text is the heavy part.
*/
export default function ShoppingProductPage() {
const t = useTranslations('shopping.detail');
@@ -31,6 +38,8 @@ export default function ShoppingProductPage() {
detail: ShoppingProductDetail | null | 'failed';
} | null>(null);
const key = `${activeBrandId}:${productId}:${prompt ?? ''}:${platform ?? ''}`;
+ const [says, setSays] = useState<{ key: string; says: ProductAiSays | null } | null>(null);
+ const saysKey = `${activeBrandId}:${productId}`;
useEffect(() => {
if (!activeBrandId || !productId) return;
@@ -53,6 +62,22 @@ export default function ShoppingProductPage() {
};
}, [activeBrandId, productId, key, prompt, platform]);
+ useEffect(() => {
+ if (!activeBrandId || !productId) return;
+ let cancelled = false;
+ getProductAiSays(activeBrandId, productId, { datePreset: '30d' })
+ .then((read) => {
+ if (!cancelled) setSays({ key: saysKey, says: read });
+ })
+ .catch((err) => {
+ console.error('Failed to read what AI says about the product:', err);
+ if (!cancelled) setSays({ key: saysKey, says: null });
+ });
+ return () => {
+ cancelled = true;
+ };
+ }, [activeBrandId, productId, saysKey]);
+
const back = (
<Link
href="/dashboard/shopping?tab=products"
@@ -91,7 +116,11 @@ export default function ShoppingProductPage() {
return (
<div className="space-y-6">
{back}
- <ProductDetailView detail={detail} brandId={activeBrandId ?? undefined} />
+ <ProductDetailView
+ detail={detail}
+ brandId={activeBrandId ?? undefined}
+ aiSays={says?.key === saysKey ? says.says : undefined}
+ />
</div>
);
}
diff --git a/web/src/lib/actions/shopping-product-detail.test.ts b/web/src/lib/actions/shopping-product-detail.test.ts
index 4c3dec5d4..2de9cf29f 100644
--- a/web/src/lib/actions/shopping-product-detail.test.ts
+++ b/web/src/lib/actions/shopping-product-detail.test.ts
@@ -56,7 +56,7 @@ vi.mock('@/lib/supabase/server', () => ({
})),
}));
-const { getShoppingProductDetail } = await import('./shopping');
+const { getProductAiSays, getShoppingProductDetail } = await import('./shopping');
beforeEach(() => {
tables = {};
@@ -209,6 +209,61 @@ describe('getShoppingProductDetail', () => {
});
});
+describe('getProductAiSays (ECOM-012)', () => {
+ it('quotes the answers that showed the product, with the sources they cited', async () => {
+ await expect(getProductAiSays(BRAND, 'nope', { datePreset: '30d' })).rejects.toThrow('invalid');
+ expect(await getProductAiSays(BRAND, PRODUCT, { datePreset: '30d' })).toEqual({
+ answers: 0,
+ quotes: [],
+ sources: [],
+ });
+ tables.catalog_products = [{ title: 'Ridge 30L Backpack' }];
+ tables.prompt_result_shopping_cards = [
+ { prompt_result_id: 'r1', product_title: 'Ridge 30L - Black', created_at: '2026-10-27' },
+ { prompt_result_id: 'r0', product_title: null, created_at: '2026-10-20' },
+ ];
+ tables.prompt_results = [
+ {
+ id: 'r1',
+ platform: 'chatgpt-shopping',
+ created_at: '2026-10-27T08:00:00Z',
+ response: 'Pick the **Ridge 30L** for its warranty. Others are lighter.',
+ prompt: { text: 'best 30L hiking backpack' },
+ },
+ ];
+ tables.prompt_result_citations = [
+ {
+ prompt_result_id: 'r1',
+ url: {
+ url: 'https://outdoorgear.example/best',
+ domain: 'outdoorgear.example',
+ title: null,
+ },
+ },
+ { prompt_result_id: 'r1', url: null },
+ ];
+ expect(await getProductAiSays(BRAND, PRODUCT, { datePreset: '30d' })).toEqual({
+ answers: 2,
+ quotes: [
+ {
+ text: 'Pick the Ridge 30L for its warranty.',
+ platform: 'chatgpt-shopping',
+ at: '2026-10-27T08:00:00Z',
+ promptText: 'best 30L hiking backpack',
+ },
+ ],
+ sources: [
+ {
+ url: 'https://outdoorgear.example/best',
+ domain: 'outdoorgear.example',
+ title: null,
+ answers: 1,
+ },
+ ],
+ });
+ });
+});
+
describe('the re-check read (ECOM-018)', () => {
it('reads the cards of many questions a hundred ids at a time', async () => {
tables.catalog_products = [{ id: PRODUCT, title: 'Ridge 30L Backpack', description: null }];
diff --git a/web/src/lib/actions/shopping.ts b/web/src/lib/actions/shopping.ts
index f097d4836..42986ed1e 100644
--- a/web/src/lib/actions/shopping.ts
+++ b/web/src/lib/actions/shopping.ts
@@ -28,6 +28,7 @@ import {
type ProductShelfLine,
} from '@/lib/shopping/product-detail';
import { priceText } from '@/lib/shopping/price';
+import { productAiSays, type AiSaysAnswer, type ProductAiSays } from '@/lib/shopping/ai-says';
import { FROM_PRODUCTS_KINDS } from '@/lib/action-center/registry';
import {
RECHECK_DAYS,
@@ -1805,6 +1806,111 @@ export async function getShoppingProductDetail(
};
}
+// ── What AI says about a product (Product Visibility, ECOM-012) ───────────────
+
+/** The product's cards read at most, the latest first, for its answers. */
+const AI_SAYS_CARDS = 200;
+/** Answers quoted from at most, the latest: their whole text is read. */
+const AI_SAYS_QUOTED = 8;
+/** Answers whose sources are counted, the latest. */
+const AI_SAYS_CITED = 20;
+
+/**
+ * "What AI says" about a product (ECOM-012, V1): the answers in the period
+ * that showed it, quoted where they name it, and the sources they cited
+ * (lib/shopping/ai-says.ts). Read apart from the product's page, which it
+ * follows: the answers' text is the heavy part. Through the member's
+ * session (RLS).
+ */
+export async function getProductAiSays(
+ brandId: string,
+ productId: string,
+ filters: ShoppingFilters,
+): Promise<ProductAiSays> {
+ if (!z.guid().safeParse(brandId).success || !z.guid().safeParse(productId).success) {
+ throw new Error('invalid');
+ }
+ const supabase = await createClient();
+ const [cards, product] = await Promise.all([
+ cardsInWindow(supabase, brandId, filters, 'prompt_result_id, product_title, created_at')
+ .eq('catalog_product_id', productId)
+ .order('created_at', { ascending: false })
+ .limit(AI_SAYS_CARDS),
+ supabase
+ .from('catalog_products')
+ .select('title')
+ .eq('brand_id', brandId)
+ .eq('id', productId)
+ .maybeSingle(),
+ ]);
+ if (cards.error) throw new Error(cards.error.message);
+ if (product.error) throw new Error(product.error.message);
+
+ // The answers, the latest first, with how each one's cards titled the product.
+ const titlesOf = new Map<string, string[]>();
+ for (const card of (cards.data ?? []) as unknown as {
+ prompt_result_id: string;
+ product_title: string | null;
+ }[]) {
+ const titles = titlesOf.get(card.prompt_result_id) ?? [];
+ if (card.product_title?.trim()) titles.push(card.product_title.trim());
+ titlesOf.set(card.prompt_result_id, titles);
+ }
+ const ids = [...titlesOf.keys()];
+ if (!ids.length) return { answers: 0, quotes: [], sources: [] };
+ const [answers, citations] = await Promise.all([
+ supabase
+ .from('prompt_results')
+ .select('id, platform, created_at, response, prompt:prompt_id ( text )')
+ .eq('brand_id', brandId)
+ .in('id', ids.slice(0, AI_SAYS_QUOTED)),
+ supabase
+ .from('prompt_result_citations')
+ .select('prompt_result_id, url:url_id ( url, domain, title )')
+ .eq('brand_id', brandId)
+ .in('prompt_result_id', ids.slice(0, AI_SAYS_CITED)),
+ ]);
+ if (answers.error) throw new Error(answers.error.message);
+ if (citations.error) throw new Error(citations.error.message);
+ const answerRows = (answers.data ?? []) as unknown as {
+ id: string;
+ platform: string;
+ created_at: string;
+ response: string | null;
+ prompt: { text: string } | null;
+ }[];
+ const citationRows = (citations.data ?? []) as unknown as {
+ prompt_result_id: string;
+ url: { url: string; domain: string; title: string | null } | null;
+ }[];
+ return productAiSays(
+ answerRows.map(
+ (row): AiSaysAnswer => ({
+ promptResultId: row.id,
+ platform: row.platform,
+ at: row.created_at,
+ promptText: row.prompt?.text ?? null,
+ response: row.response ?? '',
+ titles: titlesOf.get(row.id) ?? [],
+ }),
+ ),
+ citationRows.flatMap((row) =>
+ row.url
+ ? [
+ {
+ promptResultId: row.prompt_result_id,
+ url: row.url.url,
+ domain: row.url.domain,
+ title: row.url.title,
+ },
+ ]
+ : [],
+ ),
+ product.data?.title ? [product.data.title] : [],
+ ids.length,
+ );
+}
+
// ── Re-check after a done action (Product Visibility, ECOM-018) ───────────────
/** Done actions this recent are re-checked: older ones say little about the shelf now. */
diff --git a/web/src/lib/mention-match.ts b/web/src/lib/mention-match.ts
index e378a801f..147d05077 100644
--- a/web/src/lib/mention-match.ts
+++ b/web/src/lib/mention-match.ts
@@ -32,6 +32,11 @@ function namesRegex(terms: string[]): RegExp | null {
return unique.length > 0 ? new RegExp(unique.map(namePattern).join('|'), 'giu') : null;
}
+/** Whether a text names one of the terms, as tracking finds a name. */
+export function namesAny(text: string, terms: string[]): boolean {
+ return namesRegex(terms)?.test(text) ?? false;
+}
+
/** "[label](https://…)" → "label"; bare URLs dropped. */
function stripUrls(text: string): string {
return text.replace(/\[([^\]]*)\]\([^)]+\)/g, '$1').replace(/https?:\/\/[^\s)>\]]+/g, '');
diff --git a/web/src/lib/shopping/ai-says.test.ts b/web/src/lib/shopping/ai-says.test.ts
new file mode 100644
index 000000000..c56983829
--- /dev/null
+++ b/web/src/lib/shopping/ai-says.test.ts
@@ -0,0 +1,110 @@
+import { describe, expect, it } from 'vitest';
+import { productAiSays, productNames, productQuote, type AiSaysAnswer } from './ai-says';
+
+/** "What AI says" about a product (ECOM-012, V1). */
+
+describe('productNames', () => {
+ it('takes each title, and its name before the variant', () => {
+ expect(
+ productNames(['Ridge 30L Backpack - Black', 'Northwind Ridge 30L Backpack (2026)', 'Ridge']),
+ ).toEqual([
+ 'Ridge 30L Backpack - Black',
+ 'Ridge 30L Backpack',
+ 'Northwind Ridge 30L Backpack (2026)',
+ 'Northwind Ridge 30L Backpack',
+ 'Ridge',
+ ]);
+ });
+});
+
+describe('productQuote', () => {
+ const response = [
+ '## Best 30L packs',
+ '',
+ 'For most hikers the **Summit Daypack 30** is the pick.',
+ '- The [Ridge 30L Backpack](https://northwind.example/ridge) is tougher, with a lifetime warranty, but heavier at 1.4 kg.',
+ '- TrailCo Lite 28 is the cheapest.',
+ ].join('\n');
+
+ it('quotes the first sentence naming the product, as the reader sees it', () => {
+ expect(productQuote(response, ['Ridge 30L Backpack'])).toBe(
+ 'The Ridge 30L Backpack is tougher, with a lifetime warranty, but heavier at 1.4 kg.',
+ );
+ });
+
+ it('quotes nothing when the answer never names it', () => {
+ expect(productQuote(response, ['Peak 40'])).toBeNull();
+ expect(productQuote(response, [])).toBeNull();
+ });
+});
+
+describe('productAiSays', () => {
+ const answer = (over: Partial<AiSaysAnswer>): AiSaysAnswer => ({
+ promptResultId: 'r1',
+ platform: 'chatgpt-shopping',
+ at: '2026-10-27T08:00:00Z',
+ promptText: 'best 30L hiking backpack',
+ response: 'The Ridge 30L Backpack is tough. Others are lighter.',
+ titles: ['Ridge 30L Backpack - Black'],
+ ...over,
+ });
+
+ it('quotes each answer once, the latest first, and counts the sources they cited', () => {
+ const says = productAiSays(
+ [
+ answer({ promptResultId: 'r0', at: '2026-10-20T08:00:00Z', response: 'Ridge is fine.' }),
+ answer({}),
+ // The same words in another answer: quoted once.
+ answer({ promptResultId: 'r2', at: '2026-10-25T08:00:00Z', platform: 'gemini-web' }),
+ answer({
+ promptResultId: 'r3',
+ at: '2026-10-26T08:00:00Z',
+ response: 'Northwind Ridge 30L is the warranty pick.',
+ titles: ['Northwind Ridge 30L'],
+ }),
+ ],
+ [
+ {
+ promptResultId: 'r1',
+ url: 'https://outdoorgear.example/best',
+ domain: 'outdoorgear.example',
+ title: 'Best packs',
+ },
+ {
+ promptResultId: 'r2',
+ url: 'https://outdoorgear.example/best',
+ domain: 'outdoorgear.example',
+ title: 'Best packs',
+ },
+ {
+ promptResultId: 'r2',
+ url: 'https://outdoorgear.example/best',
+ domain: 'outdoorgear.example',
+ title: 'Best packs',
+ },
+ {
+ promptResultId: 'r3',
+ url: 'https://reddit.example/r/hiking',
+ domain: 'reddit.example',
+ title: null,
+ },
+ ],
+ ['Ridge 30L Backpack'],
+ 12,
+ );
+ expect(says.answers).toBe(12);
+ expect(says.quotes.map((q) => [q.text, q.platform])).toEqual([
+ ['The Ridge 30L Backpack is tough.', 'chatgpt-shopping'],
+ ['Northwind Ridge 30L is the warranty pick.', 'chatgpt-shopping'],
+ ]);
+ expect(says.sources).toEqual([
+ {
+ url: 'https://outdoorgear.example/best',
+ domain: 'outdoorgear.example',
+ title: 'Best packs',
+ answers: 2,
+ },
+ { url: 'https://reddit.example/r/hiking', domain: 'reddit.example', title: null, answers: 1 },
+ ]);
+ });
+});
diff --git a/web/src/lib/shopping/ai-says.ts b/web/src/lib/shopping/ai-says.ts
new file mode 100644
index 000000000..9a216f75d
--- /dev/null
+++ b/web/src/lib/shopping/ai-says.ts
@@ -0,0 +1,122 @@
+import { answerProse, mentionExcerpt, namesAny } from '@/lib/mention-match';
+import { sentencesOf } from '@/lib/content/readability';
+
+/**
+ * "What AI says" about a product (ECOM-012, V1): the answers that showed it,
+ * quoted where they name it, and the sources they cited. Their own words
+ * only, read as Mentions reads them: no AI of ours sums them up, so no
+ * cost. Pros and cons drawn from them come later.
+ */
+
+/** An answer that showed the product, as "What AI says" reads it. */
+export interface AiSaysAnswer {
+ promptResultId: string;
+ platform: string;
+ at: string;
+ promptText: string | null;
+ response: string;
+ /** How the answer's cards titled the product. */
+ titles: string[];
+}
+
+export interface AiSaysQuote {
+ text: string;
+ platform: string;
+ at: string;
+ promptText: string | null;
+}
+
+export interface AiSaysSource {
+ url: string;
+ domain: string;
+ title: string | null;
+ /** The answers that showed the product and cited it. */
+ answers: number;
+}
+
+export interface ProductAiSays {
+ /** The answers that showed the product in the period. */
+ answers: number;
+ quotes: AiSaysQuote[];
+ sources: AiSaysSource[];
+}
+
+export const MAX_QUOTES = 5;
+export const MAX_SOURCES = 5;
+
+/** Where a title's name ends and its variant starts: "Ridge 30L Backpack - Black". */
+const TITLE_TAIL = /\s+[-–—|:,(/]\s*|\s*[|,(]\s*/;
+
+/**
+ * The names an answer may call the product by: each title, and its head
+ * before " - ", " | ", ",", ":" or "(" when that keeps two words or more.
+ */
+export function productNames(titles: readonly string[]): string[] {
+ const names = new Set<string>();
+ for (const title of titles) {
+ const full = title.replace(/\s+/g, ' ').trim();
+ if (!full) continue;
+ names.add(full);
+ const head = full.split(TITLE_TAIL)[0].trim();
+ if (head.split(' ').length >= 2) names.add(head);
+ }
+ return [...names];
+}
+
+/** The answer's first sentence that names the product, cut around the name; null when none does. */
+export function productQuote(response: string, names: string[]): string | null {
+ if (!names.length) return null;
+ const sentence = sentencesOf(answerProse(response)).find((s) => namesAny(s, names));
+ return sentence ? mentionExcerpt(sentence, names) : null;
+}
+
+/**
+ * What the answers said: a quote from each, the latest first, one per text,
+ * and the sources most of them cited. `titles`: the catalog's own, beside
+ * how each answer's cards titled it; `total`: the answers that showed the
+ * product, when more than those read.
+ */
+export function productAiSays(
+ answers: readonly AiSaysAnswer[],
+ citations: readonly {
+ promptResultId: string;
+ url: string;
+ domain: string;
+ title: string | null;
+ }[],
+ titles: readonly string[],
+ total: number = answers.length,
+): ProductAiSays {
+ const latest = [...answers].sort((a, b) => (a.at < b.at ? 1 : -1));
+ const quotes: AiSaysQuote[] = [];
+ const said = new Set<string>();
+ for (const answer of latest) {
+ if (quotes.length >= MAX_QUOTES) break;
+ const text = productQuote(answer.response, productNames([...answer.titles, ...titles]));
+ if (!text || said.has(text)) continue;
+ said.add(text);
+ quotes.push({
+ text,
+ platform: answer.platform,
+ at: answer.at,
+ promptText: answer.promptText,
+ });
+ }
+ const cited = new Map<string, AiSaysSource & { by: Set<string> }>();
+ for (const citation of citations) {
+ const source = cited.get(citation.url) ?? {
+ url: citation.url,
+ domain: citation.domain,
+ title: citation.title,
+ answers: 0,
+ by: new Set<string>(),
+ };
+ source.by.add(citation.promptResultId);
+ cited.set(citation.url, source);
+ }
+ const sources = [...cited.values()]
+ .map(({ by, ...source }) => ({ ...source, answers: by.size }))
+ .sort((a, b) => b.answers - a.answers || a.domain.localeCompare(b.domain))
+ .slice(0, MAX_SOURCES);
+ return { answers: total, quotes, sources };
+}