Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

fix(prompts): hold a topic's name to 100 characters where it's typed and saved (#1678)

Cihan49ad547a2081
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/topics/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/topics/page.tsx
index f8732d65c..2d7939bd0 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/topics/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/topics/page.tsx
@@ -8,6 +8,7 @@ import {
getTopics,
updateTopic,
} from '@/lib/actions/topic';
+import { TOPIC_NAME_CHARS } from '@/lib/topic-names';
import type { Topic } from '@/types';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
@@ -155,6 +156,7 @@ export default function BrandTopicsPage({ params }: PageProps) {
{editingId === topic.id ? (
<div className="flex flex-1 items-center gap-2">
<Input
+ maxLength={TOPIC_NAME_CHARS}
value={editName}
onChange={(e) => setEditName(e.target.value)}
onKeyDown={(e) => {
@@ -266,6 +268,7 @@ export default function BrandTopicsPage({ params }: PageProps) {
<div className="flex gap-2">
<Input
placeholder="e.g. Industry, Comparison, How-to..."
+ maxLength={TOPIC_NAME_CHARS}
value={newName}
onChange={(e) => setNewName(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && newName.trim() && handleAdd()}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/_topics-tab.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/_topics-tab.tsx
index fe3a4b23c..68209aaf5 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/_topics-tab.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/_topics-tab.tsx
@@ -7,6 +7,7 @@ import { Link } from '@/i18n/navigation';
import { useBrandStore } from '@/stores/use-brand-store';
import { useUserRole } from '@/hooks/use-user-role';
import { getTopicsOverview, type TopicOverviewRow } from '@/lib/actions/topic';
+import { TOPIC_NAME_CHARS } from '@/lib/topic-names';
import { customUtcWindow } from '@/lib/topic-trend';
import type { PromptRange, PromptRangePreset } from '@/config/prompt-options';
import { TopicSuggestionsCard } from './_topic-suggestions-card';
@@ -472,6 +473,7 @@ export function TopicsTab({
<div className="flex gap-2">
<Input
placeholder="e.g. Industry, Comparison..."
+ maxLength={TOPIC_NAME_CHARS}
value={newName}
onChange={(e) => setNewName(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && newName.trim() && handleAddTopic()}
diff --git a/web/src/lib/actions/topic-suggestions.ts b/web/src/lib/actions/topic-suggestions.ts
index cd239d82b..f6ccef3e7 100644
--- a/web/src/lib/actions/topic-suggestions.ts
+++ b/web/src/lib/actions/topic-suggestions.ts
@@ -3,6 +3,7 @@
import { revalidatePath } from 'next/cache';
import { createClient } from '@/lib/supabase/server';
import { createTopic } from '@/lib/actions/topic';
+import { TOPIC_NAME_CHARS } from '@/lib/topic-names';
import { API_BASE_URL } from '@/config/api';
const AEO_SERVER_URL = API_BASE_URL;
@@ -111,7 +112,8 @@ export async function acceptTopicSuggestion(suggestionId: string): Promise<{ top
throw new Error('Suggestion not found or already processed');
}
- const topic = await createTopic(row.brand_id, row.name);
+ // A suggestion's name is the model's: cut to fit, not refused.
+ const topic = await createTopic(row.brand_id, row.name.trim().slice(0, TOPIC_NAME_CHARS));
const ack = await fetch(`${AEO_SERVER_URL}/api/topics/suggestions/${suggestionId}/accept`, {
method: 'POST',
diff --git a/web/src/lib/actions/topic.test.ts b/web/src/lib/actions/topic.test.ts
index 50ba1342b..eb1310468 100644
--- a/web/src/lib/actions/topic.test.ts
+++ b/web/src/lib/actions/topic.test.ts
@@ -139,3 +139,17 @@ describe('getTopicsOverview', () => {
expect(summary.trendDays).toHaveLength(14);
});
});
+
+describe('topic names', () => {
+ it('refuses a name past 100 characters before anything is written, trimmed first', async () => {
+ const { createTopic, createTopics, updateTopic } = await import('./topic');
+ const long = 'x'.repeat(101);
+ await expect(createTopic('b1', long)).rejects.toThrow(
+ 'Topic names are 100 characters at most.',
+ );
+ await expect(updateTopic('t1', long)).rejects.toThrow('100 characters at most');
+ await expect(createTopics('b1', ['Espresso', long])).rejects.toThrow('100 characters');
+ // Spaces around it don't count.
+ await expect(createTopic('b1', ` ${'x'.repeat(100)} `)).resolves.toBeDefined();
+ });
+});
diff --git a/web/src/lib/actions/topic.ts b/web/src/lib/actions/topic.ts
index a870019d0..35da038e4 100644
--- a/web/src/lib/actions/topic.ts
+++ b/web/src/lib/actions/topic.ts
@@ -5,6 +5,7 @@ import { computeAiVisibilityScore } from '@/lib/visibility-score';
import { API_BASE_URL } from '@/config/api';
import type { Topic } from '@/types';
import { DAY_MS, topicTrendDays, type TopicsWindow } from '@/lib/topic-trend';
+import { TOPIC_NAME_CHARS, topicNameFits } from '@/lib/topic-names';
export type { TopicsWindow } from '@/lib/topic-trend';
@@ -18,7 +19,15 @@ function mapTopicRow(row: Record<string, unknown>): Topic {
};
}
+/** Refuses a topic name past TOPIC_NAME_CHARS, before anything is written. */
+function assertTopicNames(names: string[]) {
+ if (!names.every(topicNameFits)) {
+ throw new Error(`Topic names are ${TOPIC_NAME_CHARS} characters at most.`);
+ }
+}
+
export async function createTopics(brandId: string, names: string[]): Promise<Topic[]> {
+ assertTopicNames(names);
const supabase = await createClient();
// Remove existing topics for this brand to avoid duplicates
@@ -73,6 +82,7 @@ export async function getTopicById(brandId: string, topicId: string): Promise<To
}
export async function createTopic(brandId: string, name: string): Promise<Topic> {
+ assertTopicNames([name]);
const supabase = await createClient();
const { data, error } = await supabase
@@ -86,6 +96,7 @@ export async function createTopic(brandId: string, name: string): Promise<Topic>
}
export async function updateTopic(topicId: string, name: string): Promise<Topic> {
+ assertTopicNames([name]);
const supabase = await createClient();
const { data, error } = await supabase
diff --git a/web/src/lib/ai-brand-setup.ts b/web/src/lib/ai-brand-setup.ts
index 00c65859d..fbab57e41 100644
--- a/web/src/lib/ai-brand-setup.ts
+++ b/web/src/lib/ai-brand-setup.ts
@@ -12,6 +12,7 @@
import { createClient } from '@/lib/supabase/client';
import { BROWSER_API_BASE_URL } from '@/config/api';
+import { TOPIC_NAME_CHARS } from '@/lib/topic-names';
const API_BASE = BROWSER_API_BASE_URL;
@@ -47,7 +48,7 @@ export const BRAND_SETUP_LIMITS = {
website: 200,
description: 2000,
topics: 20,
- topic: 100,
+ topic: TOPIC_NAME_CHARS,
};
/** At most `max` UTF-16 units, as the API's limits count them, never half of an emoji's pair. */
diff --git a/web/src/lib/topic-names.ts b/web/src/lib/topic-names.ts
new file mode 100644
index 000000000..d5c6f5c08
--- /dev/null
+++ b/web/src/lib/topic-names.ts
@@ -0,0 +1,11 @@
+/**
+ * The longest a topic's name may be. Setup's prompt generation takes topics
+ * up to this many characters (BRAND_SETUP_LIMITS.topic in ai-brand-setup.ts,
+ * and server/src/lib/brand-setup-input.js), and a topic is a few words, so the
+ * Topics pages stop there and the actions refuse more: a longer name would
+ * make Generate fail.
+ */
+export const TOPIC_NAME_CHARS = 100;
+
+/** Whether a topic name, trimmed, fits. */
+export const topicNameFits = (name: string) => name.trim().length <= TOPIC_NAME_CHARS;