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.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
feat(prompts): open a run's AI response inline on the prompt page (#849)
Gökhan Geyikd61989d9d459
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/insights/[id]/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/insights/[id]/page.tsxindex f3664eac9..699f1c671 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/insights/[id]/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/insights/[id]/page.tsx@@ -4,23 +4,14 @@ import { useEffect, useState } from 'react';import { useParams } from 'next/navigation';import { useRouter } from '@/i18n/navigation';import { getPromptResultById, type PromptResultWithText } from '@/lib/actions/tracking';-import { Markdown } from '@/components/ui/markdown';import { Badge } from '@/components/ui/badge';import { Button } from '@/components/ui/button';import { Card, CardContent } from '@/components/ui/card';import { Skeleton } from '@/components/ui/skeleton';-import {- ArrowLeft,- ExternalLink,- MessageSquareText,- Quote,- Eye,- Clock,- Search,-} from 'lucide-react';+import { ArrowLeft, ExternalLink, MessageSquareText, Quote, Eye, Clock } from 'lucide-react';import { cn } from '@/lib/utils';import { PLATFORM_LABELS } from '@/config/platform-labels';-import { formatSearchQuerySource, visibleSearchQueries } from './query-fanout';+import { ResponseDetail } from '@/components/results/response-detail';function SentimentBadge({ sentiment }: { sentiment: 'positive' | 'neutral' | 'negative' }) {return (@@ -69,6 +60,13 @@ export default function ResultDetailPage() {};}, [resultId]);+ // Opened in its own tab ("Open full page" on a prompt) there is no history+ // to go back to, so Back leads to the result's prompt instead.+ const goBack = () => {+ if (window.history.length > 1) router.back();+ else router.push(result ? `/dashboard/prompts/${result.promptId}` : '/dashboard/prompts');+ };+if (loading) {return (<div className="space-y-6 p-6">@@ -87,7 +85,7 @@ export default function ResultDetailPage() {<p className="text-muted-foreground text-sm mt-1">This result may have been deleted or does not exist.</p>- <Button variant="outline" className="mt-6 gap-2" onClick={() => router.back()}>+ <Button variant="outline" className="mt-6 gap-2" onClick={goBack}><ArrowLeft className="h-4 w-4" />Go back</Button>@@ -95,8 +93,6 @@ export default function ResultDetailPage() {);}- const searchQueries = visibleSearchQueries(result.searchQueries);-return (<div className="space-y-6 p-2 sm:p-6 max-w-5xl mx-auto">{/* Back button */}@@ -104,7 +100,7 @@ export default function ResultDetailPage() {variant="ghost"size="sm"className="gap-2 -ml-2 text-muted-foreground hover:text-foreground"- onClick={() => router.back()}+ onClick={goBack}><ArrowLeft className="h-4 w-4" />Back@@ -162,65 +158,7 @@ export default function ResultDetailPage() {</Card></div>- {/* AI Response */}- <Card>- <CardContent className="p-6">- <h2 className="text-sm font-medium mb-4">AI Response</h2>- <div className="prose prose-sm dark:prose-invert max-w-none">- <Markdown>{result.response}</Markdown>- </div>- </CardContent>- </Card>-- {/* Citations */}- {result.citations.length > 0 && (- <Card>- <CardContent className="p-6">- <h2 className="text-sm font-medium mb-4">Citations ({result.citations.length})</h2>- <div className="space-y-2">- {result.citations.map((cite, i) => (- <a- key={i}- href={cite.url}- target="_blank"- rel="noopener noreferrer"- className="flex items-start gap-3 rounded-lg border px-4 py-3 text-sm hover:bg-muted/50 transition-colors"- >- <ExternalLink className="h-4 w-4 mt-0.5 shrink-0 text-muted-foreground" />- <div className="min-w-0">- <p className="font-medium truncate">{cite.title || cite.url}</p>- <p className="text-muted-foreground text-xs truncate">{cite.url}</p>- </div>- </a>- ))}- </div>- </CardContent>- </Card>- )}-- {/* Query fan-out */}- {searchQueries.length > 0 && (- <Card>- <CardContent className="p-6">- <h2 className="text-sm font-medium mb-4">Query fan-out ({searchQueries.length})</h2>- <div className="space-y-2">- {searchQueries.map((item, i) => (- <div key={`${item.query}-${i}`} className="rounded-lg border px-4 py-3 text-sm">- <div className="flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between">- <div className="flex min-w-0 items-start gap-3">- <Search className="h-4 w-4 mt-0.5 shrink-0 text-muted-foreground" />- <p className="min-w-0 break-words font-medium">{item.query.trim()}</p>- </div>- <Badge variant="secondary" className="w-fit shrink-0 text-xs">- {formatSearchQuerySource(item, result.platform)}- </Badge>- </div>- </div>- ))}- </div>- </CardContent>- </Card>- )}+ <ResponseDetail result={result} variant="page" />{/* Timestamp */}<div className="flex items-center gap-2 text-xs text-muted-foreground pb-6">diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/page.tsxindex 4604de026..9ccdbaa3b 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/[id]/page.tsx@@ -7,7 +7,6 @@ import { buildCitationDetailHref } from '@/components/citations/filter-bar';import {getPromptDetail,type PromptDetailData,- type PromptResultWithText,type PromptTopSource,type PromptTopSourceUrl,} from '@/lib/actions/tracking';@@ -32,6 +31,7 @@ import {Clock,ExternalLink,Eye,+ EyeOff,Loader2,MessageSquareText,Quote,@@ -51,6 +51,7 @@ import {type PromptWorkStatus,} from '@/lib/actions/prompt-workflow';import { NotesCard, TargetUrlsCard } from './_workflow-cards';+import { ResponseDetail } from '@/components/results/response-detail';import {CategoryBadge,DomainFavicon,@@ -452,15 +453,22 @@ function PlatformResultGroup({group,expanded,onToggle,- onViewResult,}: {group: PlatformGroup;expanded: boolean;onToggle: () => void;- onViewResult: (result: PromptResultWithText) => void;}) {const visibleRuns = group.results.slice(0, 10);const hiddenCount = group.results.length - visibleRuns.length;+ // Several answers can be open at once, so two runs can be read side by side.+ const [openRuns, setOpenRuns] = useState<Set<string>>(new Set());+ const toggleRun = (id: string) =>+ setOpenRuns((prev) => {+ const next = new Set(prev);+ if (next.has(id)) next.delete(id);+ else next.add(id);+ return next;+ });return (<div className="overflow-hidden rounded-lg border">@@ -516,63 +524,96 @@ function PlatformResultGroup({Runs</p><div className="overflow-hidden rounded-md border bg-background">- {visibleRuns.map((result, index) => (- <div- key={result.id}- className={cn(- 'grid grid-cols-[1fr_auto] gap-3 px-3 py-2 text-xs sm:grid-cols-[1.4fr_90px_90px_100px_140px_40px] sm:items-center',- index > 0 && 'border-t',- )}- >- <div className="min-w-0 text-muted-foreground">- <span className="inline-flex items-center gap-1">- <Clock className="h-3 w-3" />- {formatTimestamp(result.createdAt)}- </span>- </div>- <div className="hidden text-center tabular-nums sm:block">- <span className="font-semibold">{result.mentionCount}</span>- <span className="text-muted-foreground"> mentions</span>- </div>- <div className="hidden text-center tabular-nums sm:block">- <span className="font-semibold">{result.citationCount}</span>- <span className="text-muted-foreground"> citations</span>- </div>- <div className="hidden justify-center sm:flex">- <SentimentBadge sentiment={result.sentiment} />- </div>- <div className="hidden sm:block">- <VisibilityBar score={result.visibilityScore} />- </div>- <Button- variant="ghost"- size="icon"- className="h-6 w-6 justify-self-end"- title="View response detail"- onClick={(event) => {- event.stopPropagation();- onViewResult(result);- }}- aria-label="View response details"- >- <Eye className="h-3.5 w-3.5" />- </Button>- <div className="col-span-2 flex flex-wrap items-center gap-2 sm:hidden">- <span className="tabular-nums">- <span className="font-semibold">{result.mentionCount}</span>- <span className="text-muted-foreground"> mentions</span>- </span>- <span className="tabular-nums">- <span className="font-semibold">{result.citationCount}</span>- <span className="text-muted-foreground"> citations</span>- </span>- <SentimentBadge sentiment={result.sentiment} />- <div className="w-32">- <VisibilityBar score={result.visibilityScore} />+ {visibleRuns.map((result, index) => {+ const open = openRuns.has(result.id);+ return (+ <div key={result.id} className={cn(index > 0 && 'border-t')}>+ <div+ role="button"+ tabIndex={0}+ aria-expanded={open}+ onClick={() => toggleRun(result.id)}+ onKeyDown={(event) => {+ if (event.target !== event.currentTarget) return;+ if (event.key === 'Enter' || event.key === ' ') {+ event.preventDefault();+ toggleRun(result.id);+ }+ }}+ className={cn(+ 'grid cursor-pointer grid-cols-[1fr_auto] gap-3 px-3 py-2 text-xs transition-colors hover:bg-muted/50 sm:grid-cols-[1.4fr_90px_90px_100px_140px_40px] sm:items-center',+ open && 'bg-muted/40',+ )}+ >+ <div className="min-w-0 text-muted-foreground">+ <span className="inline-flex items-center gap-1">+ <Clock className="h-3 w-3" />+ {formatTimestamp(result.createdAt)}+ </span>+ </div>+ <div className="hidden text-center tabular-nums sm:block">+ <span className="font-semibold">{result.mentionCount}</span>+ <span className="text-muted-foreground"> mentions</span>+ </div>+ <div className="hidden text-center tabular-nums sm:block">+ <span className="font-semibold">{result.citationCount}</span>+ <span className="text-muted-foreground"> citations</span>+ </div>+ <div className="hidden justify-center sm:flex">+ <SentimentBadge sentiment={result.sentiment} />+ </div>+ <div className="hidden sm:block">+ <VisibilityBar score={result.visibilityScore} />+ </div>+ <Button+ variant={open ? 'secondary' : 'ghost'}+ size="icon"+ className="h-6 w-6 justify-self-end"+ title={open ? 'Hide response' : 'Show response'}+ aria-label={open ? 'Hide response' : 'Show response'}+ aria-expanded={open}+ onClick={(event) => {+ event.stopPropagation();+ toggleRun(result.id);+ }}+ >+ {open ? <EyeOff className="h-3.5 w-3.5" /> : <Eye className="h-3.5 w-3.5" />}+ </Button>+ <div className="col-span-2 flex flex-wrap items-center gap-2 sm:hidden">+ <span className="tabular-nums">+ <span className="font-semibold">{result.mentionCount}</span>+ <span className="text-muted-foreground"> mentions</span>+ </span>+ <span className="tabular-nums">+ <span className="font-semibold">{result.citationCount}</span>+ <span className="text-muted-foreground"> citations</span>+ </span>+ <SentimentBadge sentiment={result.sentiment} />+ <div className="w-32">+ <VisibilityBar score={result.visibilityScore} />+ </div>+ </div></div>++ {open && (+ <div className="border-t bg-background px-4 py-4">+ <div className="mb-3 flex justify-end">+ <Link+ href={`/dashboard/insights/${result.id}`}+ target="_blank"+ rel="noopener noreferrer"+ className="inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground"+ >+ Open full page+ <ExternalLink className="h-3 w-3" />+ </Link>+ </div>+ <ResponseDetail result={result} variant="compact" />+ </div>+ )}</div>- </div>- ))}+ );+ })}</div>{hiddenCount > 0 && (<p className="mt-2 text-xs text-muted-foreground">@@ -867,7 +908,6 @@ export default function PromptDetailPage() {group={group}expanded={expanded.has(group.key)}onToggle={() => togglePlatform(group.key)}- onViewResult={(result) => router.push(`/dashboard/insights/${result.id}`)}/>)))}diff --git a/web/src/app/[locale]/(dashboard)/dashboard/insights/[id]/query-fanout.test.ts b/web/src/components/results/query-fanout.test.tssimilarity index 100%rename from web/src/app/[locale]/(dashboard)/dashboard/insights/[id]/query-fanout.test.tsrename to web/src/components/results/query-fanout.test.tsdiff --git a/web/src/app/[locale]/(dashboard)/dashboard/insights/[id]/query-fanout.ts b/web/src/components/results/query-fanout.tssimilarity index 100%rename from web/src/app/[locale]/(dashboard)/dashboard/insights/[id]/query-fanout.tsrename to web/src/components/results/query-fanout.tsdiff --git a/web/src/components/results/response-detail.tsx b/web/src/components/results/response-detail.tsxnew file mode 100644index 000000000..f92d81307--- /dev/null+++ b/web/src/components/results/response-detail.tsx@@ -0,0 +1,138 @@+'use client';++import { useState } from 'react';+import { ExternalLink, Search } from 'lucide-react';+import type { PromptResultWithText } from '@/lib/actions/tracking';+import { Markdown } from '@/components/ui/markdown';+import { Badge } from '@/components/ui/badge';+import { Button } from '@/components/ui/button';+import { Card, CardContent } from '@/components/ui/card';+import { cn } from '@/lib/utils';+import { formatSearchQuerySource, visibleSearchQueries } from './query-fanout';++/** Past this length the compact view folds the answer behind "Show full response". */+const FOLD_AT_CHARS = 1200;++/**+ * One AI answer's body: the response itself, the sources it cited and the+ * search queries the engine fanned out to.+ *+ * `page` is the standalone result page's card layout; `compact` sits inside a+ * run row on the prompt detail page, where several can be open at once, so it+ * drops the card chrome and folds long answers.+ */+export function ResponseDetail({+ result,+ variant,+}: {+ result: PromptResultWithText;+ variant: 'page' | 'compact';+}) {+ const compact = variant === 'compact';+ const searchQueries = visibleSearchQueries(result.searchQueries);+ const foldable = compact && result.response.length > FOLD_AT_CHARS;+ const [unfolded, setUnfolded] = useState(false);+ const folded = foldable && !unfolded;++ return (+ <div className={compact ? 'space-y-4' : 'space-y-6'}>+ <Section title="AI Response" compact={compact}>+ <div className={cn('relative', folded && 'max-h-72 overflow-hidden')}>+ <div className="prose prose-sm dark:prose-invert max-w-none">+ <Markdown>{result.response}</Markdown>+ </div>+ {folded && (+ <div className="pointer-events-none absolute inset-x-0 bottom-0 h-16 bg-gradient-to-t from-background to-transparent" />+ )}+ </div>+ {foldable && (+ <Button+ variant="link"+ size="sm"+ className="mt-1 h-auto px-0 text-xs"+ onClick={() => setUnfolded((v) => !v)}+ >+ {unfolded ? 'Show less' : 'Show full response'}+ </Button>+ )}+ </Section>++ {result.citations.length > 0 && (+ <Section title={`Citations (${result.citations.length})`} compact={compact}>+ <div className="space-y-2">+ {result.citations.map((cite, i) => (+ <a+ key={i}+ href={cite.url}+ target="_blank"+ rel="noopener noreferrer"+ className={cn(+ 'flex items-start gap-3 rounded-lg border text-sm transition-colors hover:bg-muted/50',+ compact ? 'px-3 py-2' : 'px-4 py-3',+ )}+ >+ <ExternalLink className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />+ <div className="min-w-0">+ <p className="truncate font-medium">{cite.title || cite.url}</p>+ <p className="truncate text-xs text-muted-foreground">{cite.url}</p>+ </div>+ </a>+ ))}+ </div>+ </Section>+ )}++ {searchQueries.length > 0 && (+ <Section title={`Query fan-out (${searchQueries.length})`} compact={compact}>+ <div className="space-y-2">+ {searchQueries.map((item, i) => (+ <div+ key={`${item.query}-${i}`}+ className={cn('rounded-lg border text-sm', compact ? 'px-3 py-2' : 'px-4 py-3')}+ >+ <div className="flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between">+ <div className="flex min-w-0 items-start gap-3">+ <Search className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />+ <p className="min-w-0 break-words font-medium">{item.query.trim()}</p>+ </div>+ <Badge variant="secondary" className="w-fit shrink-0 text-xs">+ {formatSearchQuerySource(item, result.platform)}+ </Badge>+ </div>+ </div>+ ))}+ </div>+ </Section>+ )}+ </div>+ );+}++function Section({+ title,+ compact,+ children,+}: {+ title: string;+ compact: boolean;+ children: React.ReactNode;+}) {+ if (compact) {+ return (+ <section>+ <p className="mb-2 text-[10px] font-medium uppercase tracking-wide text-muted-foreground">+ {title}+ </p>+ {children}+ </section>+ );+ }+ return (+ <Card>+ <CardContent className="p-6">+ <h2 className="mb-4 text-sm font-medium">{title}</h2>+ {children}+ </CardContent>+ </Card>+ );+}