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(server): generate content opportunities and briefs in the brand's language (#640)

Patel Dhritb3b6c3b673ee
diff --git a/server/src/lib/opportunity-generator.js b/server/src/lib/opportunity-generator.js
index 89321f027..1f5d8da25 100644
--- a/server/src/lib/opportunity-generator.js
+++ b/server/src/lib/opportunity-generator.js
@@ -6,6 +6,7 @@
import { generateObject } from 'ai';
import { z } from 'zod';
import { resolveModel } from './ai-provider.js';
+import { getLanguageName } from './languages.js';
import supabaseAdmin from '../config/supabase.js';
import { logger } from './logger.js';
@@ -64,11 +65,13 @@ export async function generateContentOpportunities(brandId) {
const { data: brand } = await supabaseAdmin
.from('brands')
- .select('id, name, description, industry')
+ .select('id, name, description, industry, language')
.eq('id', brandId)
.single();
if (!brand) return;
+ const langName = getLanguageName(brand.language);
+
const { data: domains } = await supabaseAdmin
.from('brand_domains')
.select('domain')
@@ -161,7 +164,9 @@ Competitors: ${(compRes.data || []).map((c) => c.name).join(', ') || 'None'}
Prompt Data:
${scored.map((p, i) => `[${i}] "${p.text}" | Intent: ${p.intent} | AI Vol: ${p.estAiVolume}/mo | Vis: ${p.avgVisibility}% | Gap: ${p.competitorGap}%`).join('\n')}
-Generate actionable content opportunities.`;
+Generate actionable content opportunities.
+
+IMPORTANT: Write every opportunity title and description in ${langName}.`;
const { object } = await generateObject({
model: resolveModel(),
diff --git a/server/src/routes/content.js b/server/src/routes/content.js
index d1fe8eb76..57a59f8ee 100644
--- a/server/src/routes/content.js
+++ b/server/src/routes/content.js
@@ -11,6 +11,7 @@ import {
import { createJob, getJob } from '../lib/job-manager.js';
import { runContentJob } from '../lib/job-runner.js';
import { resolveModel } from '../lib/ai-provider.js';
+import { getLanguageName } from '../lib/languages.js';
import supabaseAdmin from '../config/supabase.js';
import {
assertBrandAccess,
@@ -601,10 +602,12 @@ export async function generateBriefForOpportunity(opportunityId, { force = false
const { data: brand } = await supabaseAdmin
.from('brands')
- .select('name, industry, description, organization_id')
+ .select('name, industry, description, organization_id, language')
.eq('id', opportunity.brand_id)
.single();
+ const langName = getLanguageName(brand?.language);
+
// Quota is charged to the opportunity's org, and enforced here in the
// shared core so the dashboard route and the internal MCP route draw
// from the same monthly pool. Cached reads above never hit this.
@@ -673,7 +676,9 @@ Competitors Cited: ${(sourceData.competitorsCited || []).join(', ') || 'none'}
Latest Results Summary:
${latestResults.map((r) => `- ${r.platform}: visibility ${r.visibility_score}%, mentions: ${r.mention_count}, citations: ${r.citation_count}, sentiment: ${r.sentiment}`).join('\n') || 'No results yet'}
-Generate a detailed content brief for this opportunity.`;
+Generate a detailed content brief for this opportunity.
+
+IMPORTANT: Write every brief field in ${langName}.`;
const aiModel = resolveModel(model);