Repository navigation
feat(topics): persisted AI topic suggestions on the Topics page - #497
Merged
Merged
Conversation
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.
7 tasks done
6 tasks done
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
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
topic_suggestionstable (00030) mirroringprompt_suggestions: statusnew / added / dismissed,added_topic_idbackref, RLS (member select, admin/manager/analyst update). Applied to the hosted project.Server
POST /api/topics/suggest(web research → structured extraction,withRetryfrom fix(onboarding): retry LLM suggestion calls and fall back to manual entry #443) is extracted into a sharedgenerateTopicIdeashelper — onboarding behavior unchanged.assertBrandAccess.prompt_volumes+prompt_resultsfor 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).topic_suggestionsplan 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
TopicSuggestionsCardbetween 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 withoutcanManage,#topic-opportunitiesanchor that expands + scrolls on deep links.createTopicaction (never the pluralcreateTopics, which replaces the brand's whole topic list)./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 featureHow to test
/dashboard/topicsas admin/manager — a collapsed "Topic Suggestions" strip sits between the KPIs and the leaderboard; page load fires no suggestion requests (check the network tab)./dashboard/insights→ the "Topic Opportunities" teaser links to/dashboard/topics#topic-opportunities, which expands and scrolls to the card from a cold load.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)