Skip to content

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

fix(branding): pick a Jev secondary button merge will keep (#4979)

Abimael Martell7120d1692654
diff --git a/apps/api/src/__tests__/lib/branding/jev.test.ts b/apps/api/src/__tests__/lib/branding/jev.test.ts
index 457097f29..5c4b31408 100644
--- a/apps/api/src/__tests__/lib/branding/jev.test.ts
+++ b/apps/api/src/__tests__/lib/branding/jev.test.ts
@@ -466,6 +466,40 @@ describe("branding with Jev", () => {
expect(result.buttonClassification.confidence).toBeCloseTo(0.48);
});
+ it("skips a secondary button that looks like the primary, since merge would drop it", async () => {
+ const input = baseInput(new CostTracking());
+ input.buttons.push({
+ ...input.buttons[0],
+ index: 2,
+ text: "Start free trial",
+ });
+ respondWith(
+ jevResponse({
+ secondary_button: {
+ type: "choice",
+ choice: "button_2",
+ probabilities: {
+ button_0: 0.1,
+ button_1: 0.3,
+ button_2: 0.55,
+ none: 0.05,
+ },
+ confidence: 0.5,
+ },
+ }),
+ );
+
+ const result = await enhanceBrandingWithLLM(input);
+
+ expect(result.buttonClassification.secondaryButtonIndex).toBe(1);
+ const merged = mergeBrandingResults(
+ input.jsAnalysis,
+ result,
+ input.buttons,
+ );
+ expect(merged.components?.buttonSecondary?.background).toBe("transparent");
+ });
+
it("falls back to the LLM when the TypeSafe API errors", async () => {
mocks.systemOne.mockRejectedValueOnce(new Error("invalid api key"));
const costTracking = new CostTracking();
diff --git a/apps/api/src/lib/branding/jev.ts b/apps/api/src/lib/branding/jev.ts
index 7e4e7b3fc..df17a3a49 100644
--- a/apps/api/src/lib/branding/jev.ts
+++ b/apps/api/src/lib/branding/jev.ts
@@ -311,6 +311,8 @@ type JevRequest = {
buttonCount: number;
/** Background + text color per button, to group look-alike buttons. */
buttonStyles: string[];
+ /** Raw background per button: merge drops a secondary that matches the primary's. */
+ buttonBackgrounds: string[];
};
export function buildJevRequest(input: BrandingLLMInput): JevRequest {
@@ -563,6 +565,7 @@ export function buildJevRequest(input: BrandingLLMInput): JevRequest {
logoCount: logos.length,
buttonCount: buttons.length,
buttonStyles: buttons.map(buttonStyle),
+ buttonBackgrounds: buttons.map(b => b.background),
};
}
@@ -623,15 +626,24 @@ function mapJevAnswers(
const { answers } = response;
const tag = `jev ${response.model}`;
- // Buttons: secondary must differ from primary.
+ // Buttons: the secondary must not share the primary's background, or merge
+ // drops it. Skip every look-alike, not just the primary itself.
const primaryButton = choiceOf(answers, "primary_button");
const secondaryButton = choiceOf(answers, "secondary_button");
const primaryButtonIndex = indexOf(primaryButton?.choice, "button");
+ const primaryBackground = request.buttonBackgrounds[primaryButtonIndex];
+ const looksLikePrimary = (option: string) =>
+ option === primaryButton?.choice ||
+ (primaryBackground !== undefined &&
+ request.buttonBackgrounds[indexOf(option, "button")] ===
+ primaryBackground);
let secondaryOption = secondaryButton?.choice;
- if (secondaryButton && secondaryOption === primaryButton?.choice) {
+ if (secondaryButton && secondaryOption && looksLikePrimary(secondaryOption)) {
secondaryOption = bestExcluding(
secondaryButton,
- new Set([primaryButton!.choice]),
+ new Set(
+ Object.keys(secondaryButton.probabilities).filter(looksLikePrimary),
+ ),
);
}