Repository navigation
fix(prompts): ask for a topic before adding prompts or generating suggestions - #1808
Merged
Merged
Conversation
…gestions
Prompts are grouped under topics, but a brand with none could still add
them: the Add Prompt dialog said "No topics defined yet. Add topics in brand
settings." and saved the prompt without a topic, Track buttons did the same,
and generating suggestions made topics the person never chose from the AI's
labels (findOrCreateTopic).
Server (API):
- POST /api/prompts/suggestions/:brandId/refresh and /:brandId/page answer
409 { code: 'no_topics' } for a brand with no active topic, after the
role check and before anything is generated, reserved or written.
Server actions and MCP:
- addPromptToSet (every single add: suggestions, Add All, Insights Track,
fan-out Track, AI Traffic, People Also Ask) and importPrompts (Add Prompt
dialog, bulk import) return { error, code: 'no_topics' } and write
nothing. trackPagePrompts checks before it makes a topic.
- refreshPromptSuggestions returns { ok: false, failure: 'no_topics' } as a
value; other failures still throw, as before.
- accept_prompt_suggestion says to add a topic first (accept_topic_suggestion
or Prompts > Topics), and its description says so.
- A failed topics read never counts as "no topics".
UI:
- One TopicFirstDialog / TopicFirstNotice (en.json "topicFirst") with an
"Add a topic" link to /dashboard/prompts/topics?new=1, which opens Add
Topic once and clears the param. Buttons stay visible; a click that hits
no_topics shows it.
- Add Prompt shows the notice instead of the form when the brand has no
topics; it reads topics on every open, so a topic added meanwhile counts.
- Brand > Manage prompts replaces the old "brand settings" text in both
cards and asks for a topic instead of adding one without.
- Onboarding and brand setup (savePromptSet) are unchanged: they create the
chosen topics first. Role gating (ansvisor#1763, ansvisor#1769) is unchanged.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…uggestions failed Review follow-ups on the topic-first flow. - Prompts page: "Add a topic" in Add prompt, Suggestions and Query Fan-out is a button that closes the dialog, switches to the Topics tab with showSection and asks TopicsTab to open Add Topic (openAddTopic / onAddTopicOpened). The page reads its tab from the route only when it opens, so the ?new=1 link changed the address alone after a tab switch. Insights, AI Traffic and the prompt page keep the link. - Roles: AddTopicLink, TopicFirstNotice and TopicFirstDialog read canManage. Since ansvisor#1790 only admins and managers write topics; anyone else gets managersOnly.addTopic and no link, and the dialog's button says Close. - refreshPromptSuggestions returns every failure as a value, as ansvisor#1777's reads do (apiFailure + isTransientStatus on the body read once, so no_topics stays its own): a used-up budget, a read-only workspace or the demo brand, a role refusal, an outage, no answer. The card shows them with useFailureToast (the upgrade dialog for subscription) instead of a message production hides. - Brand > Manage prompts links to that brand's own topics (/dashboard/brands/:id/topics#add-topic, as the brand card does), not the active brand's. - trackPagePrompts reads active topics only; the AI Traffic page dialog forgets a Track's no_topics on the next open; the Insights test has its own describe block. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # server/src/routes/prompts-suggestions-refresh.test.js # web/src/lib/actions/prompt-suggestions.test.ts # web/src/lib/actions/prompt-suggestions.ts
Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
previously approved these changes
Oct 30, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good. Approving.
I followed every way a prompt gets added or suggested and checked that each one now stops on a brand with no topic. The refusal happens on the server as well as in the UI, and nothing that worked before breaks.
Entry points checked
- Server actions:
addPromptToSetandimportPromptsreturnno_topicsbefore they write anything.addPromptToSetcovers single adds from Prompts, Manage prompts, suggestion accept, Add All and Insights Track (trackSuggestions), and Fan-out Track.trackPagePromptschecks before it creates any topic, which covers AI Traffic page prompts, Google-query Track and PAA Track. - API: suggestion refresh and page suggestions answer 409
no_topicsafter the brand and role checks. That's before any AI call. Refresh is only ever started by a click, so a brand without topics never gets the dialog unless someone asks for suggestions. - MCP:
accept_prompt_suggestionrefuses before it reads the prompt set, and the message points tolist_topic_suggestions/accept_topic_suggestion, which both exist. Chat's registry has no prompt-adding tool, and the REST v1 routes are read-only. - Topic scoping: every topic lookup is by
brand_idof the prompt set's own brand (or the brand already checked against the organization in MCP), so a topic from another brand can't be used. - Not affected: onboarding and Add Brand save the selected topics before
savePromptSet, and both need at least one topic to continue. The demo brand and read-only workspaces still hitassertWritable/ the 402 first. Analysts get the "ask an admin or a manager" wording with no link, which matches the server's role checks. - Embeds: none added. The new reads are
topics.select('id')/select('name')with no embed. refreshPromptSuggestionsno longer throws, and its only caller (the suggestions card) handles every result.
Tests: server refresh and page-suggestion route tests pass (18). The 23 related web test files pass (252 tests), and so do plan-row.test.ts, subscription-guard-coverage.test.ts and the demo gate tests. tsc is clean, and next build passes on this head. The PR already contains the latest main.
Merging with other open PRs: two small conflicts, both easy.
web/src/lib/actions/fanout.ts(with #1800 and the parts built on it): only the import lines. Keep both:dbClientplusaddPromptToSet, type PromptAddFailureCode.prompts/page.test.tsx(with #1814): two neighbouringvi.mockblocks. Keep both.
Follow-ups (not blocking)
savePromptSethas no topic check. Today the UI can't reach it without topics: onboarding and Add Brand save topics first, and Manage prompts checkstopics.lengthbefore a manual add. A one-linebrandHasTopicsguard (whenpromptsisn't empty) would make "the client isn't trusted" true for that path too.help/prompts/prompt-suggestions.md: "Generate and New ask you to add a topic first and open Prompts › Topics". They show the Add a topic first dialog, and its Add a topic button (admins and managers) opens Topics. Something like "…ask you to add a topic first, with an Add a topic button for admins and managers" would match.- Bulk import on a brand that has topics still saves prompts with no topic (
topic: null), the same as the Fan-out and Google-query Track cases already listed as follow-ups.
This was referenced Oct 30, 2026
gkhngyk
added a commit
to cihan-gyk/ansvisor
that referenced
this pull request
Oct 30, 2026
…to take-1866 # Conflicts: # web/src/lib/actions/prompt.ts
Merged
6 of 12 tasks
Merged
6 of 12 tasks
8 of 13 tasks
gkhngyk
pushed a commit
that referenced
this pull request
Nov 6, 2026
…and choose_plan (#2214) The three coach-skill fixes #1808, #1694 and #1671 left for a docs PR, in the MCP skill and its standalone copy: - A brand needs a topic before any prompt: accept_prompt_suggestion is refused on a brand without one (#1808). The skill says so, and offers a topic suggestion first. - list_action_history reads an action 7, 14 and 30 days after it closed (#1694): reading_day and final are documented, and an outcome before day 30 is reported as a reading so far. The outcome list gains mixed. - get_prompt_usage marks an ended plan with plan.ended and the choose_plan cta (#1671): no slot is left until a plan is chosen. Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9 (cherry picked from commit 17b7ea8) Co-authored-by: Claude <[email protected]>
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
Prompts are grouped under topics, but a brand without any topic could still get prompts, with none of them under a topic:
Now a brand needs a topic first, everywhere a prompt can be added or suggested. The product owner's request: "Topic eklemek olmazsa olmaz."
Where it applies. Each place shows the same Add a topic first notice or dialog instead of going ahead (
en.jsontopicFirst):Add a topic
/dashboard/prompts/topics?new=1, which opens Add Topic once./dashboard/brands/{id}/topics#add-topic).Server (the client isn't trusted)
addPromptToSetandimportPromptsreturn{ error, code: 'no_topics' }and write nothing. Every single-prompt path goes throughaddPromptToSet.trackPagePromptschecks before creating anything.409 { code: 'no_topics' }before any AI call or reservation.accept_prompt_suggestionsays to accept a topic suggestion first.refreshPromptSuggestionsno longer throws (fix(prompts): show suggestions' load failures plainly and retry once, instead of React #441 #1777 pattern). Budget (429), read-only/demo (402), role (403) and 5xx come back as typed failures. The card shows them withuseFailureToast, which opens the upgrade dialog forsubscription.Kept as is: onboarding and brand setup (they save topics before prompts), topic suggestions (a way to add a topic), and roles.
Help:
help/prompts/add-prompts.mdgets "Add a topic first", andhelp/prompts/prompt-suggestions.mdgets "A brand without topics".Related issue
None. Product owner's request.
Type of change
fix— Bug fixHow to test
no_topicsbefore generating.topic-first.test.tsx,prompt-topics-required.test.ts,accept-prompt-suggestion.test.ts;prompt-suggestions.test.ts;prompts-suggestions-refresh.test.jsand the AI Traffic page-suggestion route.Checklist
content-people.test.jstimed out once under load, passes alone 32/32)approved: false)Local build: typecheck OK after merging main; the local
yarn buildran out of disk and memory on this 8 GB machine (ENOSPC, then heap). CI runs the same production build on this PR.Follow-ups, not in this PR:
skills/ansvisor-aeo-coach/SKILL.md) doesn't mention the rule yet; a separate docs PR will follow.🤖 Generated with Claude Code