Skip to content

feat(topics): persisted AI topic suggestions on the Topics page - #497

Merged
gkhngyk merged 4 commits into
mainfrom
feature/topic-suggestions
Jul 21, 2026
Merged

gkhngyk merged 4 commits into
mainfrom
feature/topic-suggestions

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements persisted AI topic suggestions on the Topics page. The only AI topic generation in the product ran ephemerally during onboarding and was discarded; this makes it a permanent, reusable feature backed by the brand's own tracked data.

Data

  • New topic_suggestions table (00030) mirroring prompt_suggestions: status new / added / dismissed, added_topic_id backref, RLS (member select, admin/manager/analyst update). Applied to the hosted project.

Server

  • The two-phase generation behind POST /api/topics/suggest (web research → structured extraction, withRetry from fix(onboarding): retry LLM suggestion calls and fall back to manual entry #443) is extracted into a shared generateTopicIdeas helper — onboarding behavior unchanged.
  • New endpoints mirroring the prompt-suggestions API: list (never generates — the Topics page load path stays LLM-free), refresh, dismiss, accept ack. All brand-scoped via assertBrandAccess.
  • Refresh excludes topics the brand already tracks and previously dismissed/added names, so decided suggestions never reappear.
  • Gap signals: refresh mines prompt_volumes + prompt_results for high-volume prompts where the brand is visible in under half the answers (sorted by volume, then fewest competitors cited) plus the weakest existing topics by visible-answer rate, and injects them into the research prompt. Degrades to the profile-only flow when the brand has no data; shopping results excluded (feat(shopping): org-level "Shopping mode" toggle + ChatGPT Shopping platform + Insights isolation #155).
  • Refresh is gated behind a new topic_suggestions plan feature (requireFeature), added to every plan in both the server config and the mirrored web config — cost control per plan becomes a config edit.

Web

  • TopicSuggestionsCard between the KPI row and the leaderboard: collapsed one-line strip by default (same pattern as the prompts suggestions card, perf(insights): drop the full-table scan on load + use SQL limit/count instead of fetching all rows #313 — zero requests while collapsed), explicit Generate/Refresh button, Add/Dismiss per row, read-only without canManage, #topic-opportunities anchor that expands + scrolls on deep links.
  • Accept creates exactly one topic via the singular createTopic action (never the plural createTopics, which replaces the brand's whole topic list).
  • The Insights "Topic Opportunities" teaser now points to /dashboard/topics#topic-opportunities — the Topics page is the canonical home.

Deliberate deviation from the issue: the ~5-item cap was dropped. It predates the collapsed-by-default strip — the card can no longer push the leaderboard below the fold unless the user deliberately expands it, and an expanded card means they want to see the ideas.

Related issue

Closes #463

Type of change

  • feat — New feature

How to test

  1. Open /dashboard/topics as admin/manager — a collapsed "Topic Suggestions" strip sits between the KPIs and the leaderboard; page load fires no suggestion requests (check the network tab).
  2. Expand it → persisted suggestions load (empty state on first visit). Click Generate Suggestions → AI ideas appear and survive a reload.
  3. Add one → the topic appears in the leaderboard/manage list after refresh, existing topics untouched, suggestion leaves the list. Dismiss one → it disappears and does not come back on later refreshes.
  4. Refresh again → already-tracked topic names and dismissed names are absent from the new batch.
  5. On a brand with tracking history + volume analysis, generated ideas lean toward high-volume prompts with weak brand visibility; on a fresh brand, generation still works from the profile alone.
  6. Visit /dashboard/insights → the "Topic Opportunities" teaser links to /dashboard/topics#topic-opportunities, which expands and scrolls to the card from a cold load.
  7. As a member (non-manager): the card is read-only — no Generate/Add/Dismiss controls.

Checklist

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

gkhngyk added 4 commits July 21, 2026 17:21
Closes #463.

- topic_suggestions table (00030) mirroring prompt_suggestions: RLS
  member-select + admin/manager/analyst update, status new/added/dismissed,
  added_topic_id backref; applied to the hosted project.
- Express: the two-phase generation behind POST /api/topics/suggest is
  extracted into a shared helper and four new endpoints mirror the prompt
  suggestions API — list (never generates), refresh (generates with the
  brand's own name/industry/description/primary domain/language, then
  persists minus already-tracked topics and previously decided names),
  dismiss, and accept ack.
- Web: topic-suggestions actions (accept uses the singular createTopic —
  never the plural createTopics, which replaces the whole topic list) and a
  TopicSuggestionsCard between the KPI row and the leaderboard: collapsed
  one-line strip by default, loads persisted rows only when expanded (#313),
  explicit Generate/Refresh button, Add/Dismiss per row, capped at 5 visible,
  read-only without canManage, and a #topic-opportunities anchor that
  expands + scrolls on deep links.
- Insights: the Topic Opportunities teaser now points to
  /dashboard/topics#topic-opportunities — the Topics page is the canonical
  home for topic suggestions.
The ~5-item cap came from a design premise that predates the collapsed-
by-default strip: the card can no longer push the leaderboard below the
fold unless the user deliberately expands it, and an expanded card means
the user wants to see the ideas. Drop the slice and the queued-count
footnote.
The Topics-page refresh now mines the brand's own data before calling
the model: prompts with real AI search volume where the brand is visible
in under half the answers (sorted by volume, then by how few competitors
are cited — demand nobody owns yet) plus the weakest existing topics by
visible-answer rate. Both go into the research prompt as an opportunity
block, steering suggestions toward high-volume low-competition themes.

loadTopicSignals returns null whenever the brand has no runs or no
volume data, so generation degrades to the profile-only flow; the
onboarding endpoint passes no signals and is unchanged. Shopping results
stay excluded (#155).
… plan feature

The refresh endpoint triggers a search-grounded LLM run, so like prompt
suggestions it now goes through requireFeature. topic_suggestions is
added to every plan's feature list (server + the mirrored web config) —
no plan loses access today; the gate exists so cost control per plan is
a config edit, not a code change. List/dismiss/accept stay ungated:
they only touch persisted rows.
@gkhngyk
gkhngyk merged commit af75ce5 into main Jul 21, 2026
4 checks passed
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.

Topics: persisted AI topic suggestions between the KPI row and the leaderboard

1 participant