Skip to content

feat(prompts): Query Fan-out tab — observed sub-queries with times-searched + one-click track - #342

Merged
gkhngyk merged 2 commits into
mainfrom
feature/fanout-ui
Jul 6, 2026
Merged

gkhngyk merged 2 commits into
mainfrom
feature/fanout-ui

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

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 in prompt_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 }) — aggregates search_queries across 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).
      • engines — the source-platform slugs that surfaced it.
      • 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 via addPromptToSet (which 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 (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 the fanout tab (URL ?tab=fanout) between Prompts and Insights.
  • types/supabase.ts — adds the search_queries column to the prompt_results generated 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_queries column + 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 classifyPromptIntent LLM 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 feature

How to test

  1. From web/: yarn typecheck, yarn lint, yarn format:check, yarn test all pass.
  2. Open /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).
  3. Click + on an untracked sub-query → it's added as a tracked prompt (respects maxPrompts) and the row flips to Tracked ✓ after refetch.
  4. A brand with no fan-out yet shows the empty-state notice (no crash).

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (from web/)
  • yarn typecheck passes (from web/)
  • yarn format:check passes (from web/)
  • Changes are focused — one concern per PR

…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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread web/src/lib/actions/fanout.ts Outdated
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.
@gkhngyk
gkhngyk merged commit 03e9fe8 into main Jul 6, 2026
4 checks passed
@gkhngyk
gkhngyk deleted the feature/fanout-ui branch July 6, 2026 01:23
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.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants