Repository navigation
feat(prompts): Query Fan-out intent column — classifyPromptIntent + on-demand cache (closes #333) - #353
Merged
Conversation
…che) 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.
There was a problem hiding this comment.
Pull request overview
Adds intent classification to the Query Fan-out tab by introducing a server-side, brand-independent intent cache and a lightweight intent-only classifier, then wiring the web UI to fetch and render intent badges on-demand using a shared label/color config (aligned with Insights intent taxonomy).
Changes:
- Server: add
classifyPromptIntent(intent-only) andPOST /api/prompts/fanout-intentsthat normalizes/dedups queries, reads/writes thefanout_query_intentscache, and classifies cache misses with bounded concurrency. - DB: add migration
00022creatingfanout_query_intents(RLS enabled, no policies) and regeneratesupabase/schema.sql. - Web: add shared
intent-labelsconfig, add a server action to call the new endpoint, and render a new non-blocking Intent column in the fan-out table.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| web/src/lib/actions/fanout.ts | Adds classifyFanoutIntents() server action to call the new server endpoint with the user session token. |
| web/src/config/intent-labels.ts | New shared source of intent labels + badge colors for both Insights and Fan-out. |
| web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx | Switches Insights intent label/color usage to the shared config. |
| web/src/app/[locale]/(dashboard)/dashboard/prompts/_fanout-tab.tsx | Adds Intent column and async, on-demand intent fetching + badge rendering. |
| supabase/migrations/00022_fanout_query_intents.sql | Creates the global intent cache table with RLS enabled. |
| supabase/schema.sql | Regenerated schema including the new cache table. |
| server/src/routes/prompts.js | Adds POST /api/prompts/fanout-intents cache-read + classify-misses + upsert flow. |
| server/src/lib/intent-extraction.js | Adds intent-only schema/system prompt and classifyPromptIntent(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+546
to
+553
| // 1. Read the cache. | ||
| const { data: cached } = await supabaseAdmin | ||
| .from('fanout_query_intents') | ||
| .select('query, intent') | ||
| .in('query', queries); | ||
| const intents = {}; | ||
| for (const row of cached ?? []) intents[row.query] = row.intent; | ||
|
|
Comment on lines
+9
to
+27
| export const INTENT_LABELS: Record<string, string> = { | ||
| comparison: 'Comparison', | ||
| 'how-to': 'How-to', | ||
| 'what-is': 'What is', | ||
| 'best-top': 'Best / Top', | ||
| 'vs-review': 'vs. / Review', | ||
| recommendation: 'Recommendation', | ||
| 'problem-solving': 'Problem Solving', | ||
| }; | ||
|
|
||
| export const INTENT_COLORS: Record<string, string> = { | ||
| comparison: 'border-indigo-500/30 bg-indigo-500/10 text-indigo-600 dark:text-indigo-400', | ||
| 'how-to': 'border-violet-500/30 bg-violet-500/10 text-violet-600 dark:text-violet-400', | ||
| 'what-is': 'border-purple-400/30 bg-purple-400/10 text-purple-600 dark:text-purple-400', | ||
| 'best-top': 'border-blue-400/30 bg-blue-400/10 text-blue-600 dark:text-blue-400', | ||
| 'vs-review': 'border-cyan-500/30 bg-cyan-500/10 text-cyan-600 dark:text-cyan-400', | ||
| recommendation: 'border-emerald-500/30 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400', | ||
| 'problem-solving': 'border-amber-500/30 bg-amber-500/10 text-amber-600 dark:text-amber-400', | ||
| }; |
…pilot 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 was referenced Jul 7, 2026
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 the Intent column to the Query Fan-out tab — the final piece of #333 after the core tab shipped in #342. Each observed sub-query is labelled with the same 7-value taxonomy as the Insights "intent" column, derived on-demand and cached.
Server
intent-extraction.js—classifyPromptIntent(text, aiModel): intent-only (no keyword extraction, no volume work — a cheaper call thanextractIntentKeywords), reusing the exact enum fromintentKeywordSchemaso the two intent columns can't drift.00022—fanout_query_intents: a brand-independent cache keyed by the normalized (trimmed, whitespace-collapsed, lower-cased) sub-query. The intent of a string is the same for every brand, so one classification is reused everywhere. RLS enabled (server/service-role only; not client-exposed). Applied to the hosted DB;schema.sqlregenerated.POST /api/prompts/fanout-intents: normalize + dedup the queries, 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 — controls LLM cost.Web
config/intent-labels.ts(new) — single source forINTENT_LABELS/INTENT_COLORS, now shared by the Insights Prompt Volumes table and the fan-out tab (removed the duplicated local copy in the prompts page).actions/fanout.ts—classifyFanoutIntents(queries)→ the server route (session-token fetch, mirrors the volumes flow)._fanout-tab.tsx— Intent column between Sourced prompts and Track. Intents load on-demand and non-blocking: the table paints immediately and the badges fill in as the (cached) classifications resolve; a—shows until then.Verified live
Applied the migration, then the cache populated with real sub-queries from tracked brands — all classified into correct, valid-enum intents, e.g.:
Related issue
Closes #333. Depends on #332/#341 (the
search_queriescapture) and #342 (the core tab), both merged. The explicit non-goals from #333 stay out: no Google volume/competition, no competitor/citation coverage, no co-occurrence badge, no LLM-generated fan-out.Type of change
feat— New featureHow to test
server/:npm run lint,npm run format:check,npm run test(99) pass. Fromweb/:yarn typecheck,yarn lint,yarn format:check,yarn testpass./dashboard/prompts→ Query Fan-out: each row gets an Intent badge (Comparison / How-to / What is / Best / Top / …); it appears shortly after the table (on-demand), then is instant on later loads (cached).intent-labelsconfig).Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lint/npm run lintpassyarn typecheckpasses (fromweb/)schema.sqlregenerated