Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(branding): populate colors.secondary in branding extraction

firecrawl-spring[bot]e7b85b47568e
diff --git a/apps/api/src/lib/branding/llm.ts b/apps/api/src/lib/branding/llm.ts
index 910705ac8..cb094ffc7 100644
--- a/apps/api/src/lib/branding/llm.ts
+++ b/apps/api/src/lib/branding/llm.ts
@@ -227,6 +227,7 @@ export async function enhanceBrandingWithLLM(
},
colorRoles: {
primaryColor: "",
+ secondaryColor: "",
accentColor: "",
backgroundColor: "",
textPrimary: "",
diff --git a/apps/api/src/lib/branding/merge.ts b/apps/api/src/lib/branding/merge.ts
index f454763af..b75f7987a 100644
--- a/apps/api/src/lib/branding/merge.ts
+++ b/apps/api/src/lib/branding/merge.ts
@@ -267,6 +267,7 @@ export function mergeBrandingResults(
merged.colors = {
...merged.colors,
primary: llm.colorRoles.primaryColor || merged.colors?.primary,
+ secondary: llm.colorRoles.secondaryColor || merged.colors?.secondary,
accent: llm.colorRoles.accentColor || merged.colors?.accent,
background: llm.colorRoles.backgroundColor || merged.colors?.background,
textPrimary: llm.colorRoles.textPrimary || merged.colors?.textPrimary,
@@ -276,6 +277,7 @@ export function mergeBrandingResults(
if ((merged as any).__debug_colors) {
(merged as any).__debug_colors.llmSelectedColors = {
primary: llm.colorRoles.primaryColor,
+ secondary: llm.colorRoles.secondaryColor,
accent: llm.colorRoles.accentColor,
background: llm.colorRoles.backgroundColor,
textPrimary: llm.colorRoles.textPrimary,
diff --git a/apps/api/src/lib/branding/processor.ts b/apps/api/src/lib/branding/processor.ts
index 3df7eb2f5..9044520ee 100644
--- a/apps/api/src/lib/branding/processor.ts
+++ b/apps/api/src/lib/branding/processor.ts
@@ -207,8 +207,15 @@ function inferPalette(
yiq: contrastYIQ(hex),
}));
+ // Secondary: a chromatic color distinct from both primary and accent
+ const secondary =
+ ranked.find(
+ h => !isGrayish(h) && h !== primary && h !== accent && h !== background,
+ ) || undefined;
+
const paletteResult = {
primary,
+ secondary,
accent,
background,
textPrimary: textPrimary,
diff --git a/apps/api/src/lib/branding/prompt.ts b/apps/api/src/lib/branding/prompt.ts
index 5f0f2ff17..b5a30df02 100644
--- a/apps/api/src/lib/branding/prompt.ts
+++ b/apps/api/src/lib/branding/prompt.ts
@@ -487,6 +487,7 @@ export function buildBrandingPrompt(input: BrandingLLMInput): string {
prompt += `${buttons && buttons.length > 0 ? "3" : "1"}. **Color Roles**: Based on ${buttons && buttons.length > 0 ? "button colors and " : ""}page context:\n`;
prompt += ` - PRIMARY brand color (usually logo/heading color)\n`;
+ prompt += ` - SECONDARY brand color (a complementary color distinct from primary, often used for secondary headings, supporting UI elements, or alternate brand visuals. Return "" if no clear secondary color exists)\n`;
prompt += ` - ACCENT color (${buttons && buttons.length > 0 ? "usually the vibrant CTA button background - green, blue, etc." : "vibrant accent color from the page"})\n`;
prompt += ` - Background and text colors\n`;
prompt += ` - If unsure about any color, return an empty string "" for that field (NOT null)\n\n`;
@@ -573,7 +574,7 @@ export function buildBrandingPrompt(input: BrandingLLMInput): string {
prompt += `${fieldNumber}. buttonClassification: { primaryButtonIndex, primaryButtonReasoning, secondaryButtonIndex, secondaryButtonReasoning, confidence }\n`;
fieldNumber++;
}
- prompt += `${fieldNumber}. colorRoles: { primaryColor, accentColor, backgroundColor, textPrimary, confidence }\n`;
+ prompt += `${fieldNumber}. colorRoles: { primaryColor, secondaryColor, accentColor, backgroundColor, textPrimary, confidence }\n`;
fieldNumber++;
prompt += `${fieldNumber}. cleanedFonts: [] (array, can be empty but must be present)\n`;
if (hasLogoCandidates) {
diff --git a/apps/api/src/lib/branding/schema.ts b/apps/api/src/lib/branding/schema.ts
index 0d0b721c4..517a623ef 100644
--- a/apps/api/src/lib/branding/schema.ts
+++ b/apps/api/src/lib/branding/schema.ts
@@ -44,6 +44,11 @@ const baseBrandingEnhancementSchema = z.object({
// Color role clarification
colorRoles: z.object({
primaryColor: z.string().describe("Main brand color (hex)"),
+ secondaryColor: z
+ .string()
+ .describe(
+ "Secondary brand color (hex) - a complementary color distinct from primary, often used for secondary UI elements, headings, or supporting brand visuals. Return empty string if no clear secondary color exists.",
+ ),
accentColor: z.string().describe("Accent/CTA color (hex)"),
backgroundColor: z.string().describe("Main background color (hex)"),
textPrimary: z.string().describe("Primary text color (hex)"),