Repository navigation
feat(prompts): Query Fan-out tab — observed sub-queries with times-searched + one-click track - #342
Merged
Merged
Conversation
…rack Adds a "Query Fan-out" tab to /dashboard/prompts (between Prompts and Insights) surfacing the OBSERVED sub-queries answer engines actually ran (from prompt_results.search_queries, #332) — never predicted. (#333) - actions/fanout.ts: - getQueryFanout(brandId, { days }): aggregates search_queries across the window into distinct sub-queries, grouped by trimmed/lower-cased text. Each row carries `timesSearched` (distinct answers whose fan-out contained it — the observed demand signal, default sort), the source engines, the `sourcedPrompts` (the user's prompts whose answers ran it, linked), and `tracked`/`trackedPromptId` (already a prompt for the brand). - trackFanoutQuery(brandId, query): promotes a sub-query into a tracked prompt via addPromptToSet (enforces the plan's maxPrompts), deriving platforms/models from the brand's most recent active prompt — mirrors the Insights "accept suggestion" flow. - _fanout-tab.tsx: the table (Sub-query · Engine chip · Times searched · Sourced prompts · +/Tracked), with a clear empty state (fan-out is sparse and Copilot/Perplexity-heavy) and data-refetch-driven dedup on the "+". - page.tsx: register the 'fanout' tab (URL ?tab=fanout) between Prompts and Insights. - types/supabase.ts: add the search_queries column to prompt_results (the column shipped in #332's migration; the generated types weren't updated). Intent classification (the 7-value taxonomy column) is a deliberate fast-follow — it needs an LLM route + cache and is the heaviest piece. Explicit non-goals per #333 stay out: no Google volume/competition, no competitor/citation coverage, no co-occurrence badge, no LLM-generated fan-out.
There was a problem hiding this comment.
Pull request overview
Adds a new Query Fan-out tab to /dashboard/prompts that aggregates observed prompt_results.search_queries into distinct sub-queries (with times-searched, engine/source chips, sourced prompts) and supports one-click promotion of a sub-query into a tracked prompt.
Changes:
- Introduces server actions to aggregate observed fan-out and promote a sub-query into a tracked prompt.
- Adds a new client tab UI rendering the fan-out table with “Times searched”, “Sourced prompts”, and track/Tracked status.
- Updates Supabase generated types to include
prompt_results.search_queries.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| web/src/types/supabase.ts | Adds search_queries to prompt_results generated TypeScript types. |
| web/src/lib/actions/fanout.ts | New server actions for querying fan-out aggregation and tracking a sub-query as a prompt. |
| web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx | Registers the new fanout tab and renders the fan-out tab content. |
| web/src/app/[locale]/(dashboard)/dashboard/prompts/_fanout-tab.tsx | New client UI for the “Query fan-out” table and one-click tracking flow. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+59
to
+62
| const supabase = await createClient(); | ||
| const days = opts?.days ?? 30; | ||
| const since = new Date(Date.now() - days * 86_400_000).toISOString(); | ||
|
|
Comment on lines
+90
to
+93
| const q = typeof item?.query === 'string' ? item.query.trim() : ''; | ||
| if (!q) continue; | ||
| const key = q.toLowerCase(); | ||
|
|
…t review) - getQueryFanout clamps the `days` option to 1..90 (default 30) so a crafted call can't force an unbounded prompt_results scan + in-memory aggregation. - Add normalizeQuery(): trim + collapse internal whitespace runs to a single space, applied to the grouping key/display, the tracked-prompt dedup key, and trackFanoutQuery's stored text. Now "best laptops" and "best laptops" collapse into one row (the earlier comment claimed this but only outer whitespace was trimmed). Addresses the Copilot review on #342.
This was referenced Jul 6, 2026
Merged
gkhngyk
added a commit
that referenced
this pull request
Jul 6, 2026
Bump all packages + docker-compose image tags to 0.1.5 and write the CHANGELOG for everything merged since 0.1.4 (#283–#342): the Query Fan-out capture + tab, Citations Competitor Gaps, brand pause, Site Audit MCP tools, sortable All Prompts, structured logging Phase 2, the topic-detail perf refactor, the invite share-link fix, and more.
7 tasks done
gkhngyk
added a commit
that referenced
this pull request
Jul 6, 2026
…n-demand cache (closes #333) (#353) * feat(prompts): Query Fan-out intent column (classifyPromptIntent + cache) Adds the intent column to the Query Fan-out tab (#333) — the last piece of the feature after the core tab (#342). Each observed sub-query is labelled with the same 7-value taxonomy as the Insights "intent" column. Server: - intent-extraction.js: classifyPromptIntent(text, aiModel) — intent-only (no keywords, no volume work), reusing the exact enum from intentKeywordSchema so the two intent columns can't drift. - migration 00022: fanout_query_intents — a brand-independent cache keyed by the normalized (lower-cased) sub-query, RLS enabled (server-only). Intent of a string is the same for every brand, so one classification is reused. - POST /api/prompts/fanout-intents: normalize + dedup, read the cache, and classify only the misses (bounded concurrency 6, batch cap 200), then upsert. On-demand at read time, never during tracking ingest. Web: - config/intent-labels.ts: single source for INTENT_LABELS/COLORS, now shared by the Insights Prompt Volumes table and the fan-out tab. - actions/fanout.ts: classifyFanoutIntents(queries) → the server route. - _fanout-tab.tsx: Intent column between Sourced prompts and Track; intents load on-demand and non-blocking (the table paints first, badges fill in). Closes #333. Verified live: the route classifies real sub-queries into correct intents (comparison / how-to / what-is / best-top / …) and caches them. * fix(fanout): chunk intent cache lookup + style the "other" intent (Copilot review) - /api/prompts/fanout-intents read the cache with a single `.in('query', ...)` over up to 200 text values, which can exceed PostgREST's URL length limit, and it swallowed the Supabase error (a failed read silently classified everything via the LLM). Read in bounded chunks of 40 and throw on error. - The intent enum includes `other`, which the endpoint can return, but the shared INTENT_LABELS/COLORS omitted it — the UI rendered a raw, unstyled "other". Add an "Other" label + a neutral slate badge color (also tidies the Insights intent column for the same value). Addresses the Copilot review on #353.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a Query Fan-out tab to
/dashboard/prompts(between Prompts and Insights) that surfaces the observed query fan-out — the sub-queries answer engines actually ran while building your answers, captured inprompt_results.search_queries(#332). Observed only; we never predict sub-queries. Users can promote any of them into a tracked prompt in one click. (#333)Changes
web/src/lib/actions/fanout.ts(new)getQueryFanout(brandId, { days })— aggregatessearch_queriesacross the window into distinct sub-queries, grouped by trimmed + lower-cased text (whitespace/case variants collapse; the parser already trims on write, feat(tracking): capture & store observed query fan-out (Cloro searchQueries) #341). Each row returns:timesSearched— distinct answers (rows) whose fan-out contained it. Observed demand signal, default sort (no Google Ads volume for these long-tail queries).sourcedPrompts— the user's tracked prompts whose answers ran this sub-query (linked back).tracked/trackedPromptId— whether this exact sub-query is already a prompt for the brand.trackFanoutQuery(brandId, query)— promotes a sub-query into a tracked prompt viaaddPromptToSet(which enforces the plan'smaxPrompts), deriving platforms/models from the brand's most recent active prompt — mirrors the Insights "accept suggestion" flow._fanout-tab.tsx(new) — the table: Sub-query · Engine chip · Times searched · Sourced prompts · +/Tracked ✓, with a clear empty state (fan-out is sparse and Copilot/Perplexity-heavy) and data-refetch-driven dedup on the+(mirrors the citations "add competitor" pattern).page.tsx— registers thefanouttab (URL?tab=fanout) between Prompts and Insights.types/supabase.ts— adds thesearch_queriescolumn to theprompt_resultsgenerated types (the column shipped in feat(tracking): capture & store observed query fan-out (Cloro searchQueries / search_model_queries) #332's migration; the TS types weren't regenerated there).Depends on
#332 / #341 (the
search_queriescolumn + capture). The column is already live on the hosted DB, so the tab renders today; it fills in as Copilot/Perplexity results land post-deploy.Deliberately deferred
Intent classification (the 7-value taxonomy column) is a fast-follow — it needs a
classifyPromptIntentLLM route + a cache, the heaviest piece, and is cleaner as its own PR. The Sourced prompts column (added to #333 by request) ships here.Explicit non-goals per #333 stay out: no Google volume/competition, no competitor/citation coverage, no answer-level co-occurrence badge, no LLM-generated fan-out.
Type of change
feat— New featureHow to test
web/:yarn typecheck,yarn lint,yarn format:check,yarn testall pass./dashboard/prompts→ Query Fan-out tab. For a brand with Copilot/Perplexity runs, a list of observed sub-queries appears, sorted by Times searched, with engine chips and the Sourced prompts they came from (each linking to that prompt).maxPrompts) and the row flips to Tracked ✓ after refetch.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (fromweb/)yarn typecheckpasses (fromweb/)yarn format:checkpasses (fromweb/)