Skip to content

Simplify ad response shape#562

Merged
jahooma merged 2 commits intomainfrom
jahooma/check-gravity-ad-id
Apr 29, 2026
Merged

Simplify ad response shape#562
jahooma merged 2 commits intomainfrom
jahooma/check-gravity-ad-id

Conversation

@jahooma
Copy link
Copy Markdown
Contributor

@jahooma jahooma commented Apr 29, 2026

Summary

Simplifies the ad provider contract so Gravity and Carbon always return an ads array instead of a banner-or-choice union.
Updates the CLI ad hook, chat, and waiting room render paths to consume that array directly while preserving the choice banner behavior.
Normalizes no-fill and error responses from the ads API to the same array-based shape.

Validation

  • bun run typecheck in cli
  • bun run typecheck in web

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 29, 2026

Greptile Summary

This PR successfully simplifies the ad provider contract by replacing the banner | choice variant union with a uniform { ads: NormalizedAd[] } shape across all providers, the API route, and the CLI hook. The A/B variant assignment logic (getGravityVariant) and the separate banner cache are removed, and both render call sites are cleaned up to consume ads directly.

Confidence Score: 5/5

Safe to merge; all remaining findings are minor style suggestions.

No logic bugs or data-integrity issues found. The simplification is correct end-to-end: client, server, and provider types all agree on the new array shape. The two P2 comments are optional follow-ups.

No files require special attention.

Important Files Changed

Filename Overview
web/src/lib/ad-providers/types.ts Removed AdVariant type and simplified FetchAdResult from a banner/choice union to a plain { ads: NormalizedAd[] }
web/src/lib/ad-providers/gravity.ts Removed A/B variant logic (getGravityVariant, BANNER_PLACEMENT_ID) and now always returns { ads: [...] }; straightforward simplification.
web/src/lib/ad-providers/carbon.ts Trivially updated return value from { variant: 'choice', ads } to { ads }; no logic change.
web/src/app/api/v1/ads/_post.ts Added noAdsResponse helper and unified all response paths to { ads, variant: 'choice', provider }; variant field is vestigial but harmless.
cli/src/hooks/use-gravity-ad.ts Removed AdData/AdVariant types, banner cache, and showAd(); now uses a single ads state and choice cache path; showChoiceAds is now a trivial wrapper around setAds.
cli/src/chat.tsx Switched from adData with variant-conditional array construction to ads directly; render logic is cleaner.
cli/src/components/waiting-room-screen.tsx Same adData → ads simplification as chat.tsx; no issues.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: cli/src/hooks/use-gravity-ad.ts
Line: 183-186

Comment:
**`showChoiceAds` is now a trivial wrapper**

After removing `showAd`, `showChoiceAds` is a single-line function wrapping `setAds`. It could be inlined at its two call sites to further reduce indirection.

Then replace the two `showChoiceAds(result.ads)` / `showChoiceAds(cachedSet)` calls with `setAds(result.ads)` / `setAds(cachedSet)` directly.

**Context Used:** Find ways to simplify the implementation ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: web/src/app/api/v1/ads/_post.ts
Line: 56-61

Comment:
**Vestigial `variant` field in responses**

Now that both the CLI hook and the server-side type contract have dropped the banner/choice distinction, `variant: 'choice'` in `noAdsResponse` (and in the success/error responses in `_post.ts`) is never read by any consumer. Dropping it would complete the simplification and keep the wire format consistent with the new `FetchAdResult` shape.

```suggestion
function noAdsResponse(provider: AdProviderId) {
  return NextResponse.json(
    { ads: [], provider },
    { status: 200 },
  )
}
```

**Context Used:** Find ways to simplify the implementation ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Simplify ad response shape" | Re-trigger Greptile

Comment thread cli/src/hooks/use-gravity-ad.ts Outdated
Comment on lines 183 to 186
// Show a choice ad set (impressions are fired by the component for visible ads only)
const showChoiceAds = (ads: AdResponse[]): void => {
setAd(ads[0] ?? null) // Keep backwards compat for ad field
setAdData({ variant: 'choice', ads })
setAds(ads)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 showChoiceAds is now a trivial wrapper

After removing showAd, showChoiceAds is a single-line function wrapping setAds. It could be inlined at its two call sites to further reduce indirection.

Then replace the two showChoiceAds(result.ads) / showChoiceAds(cachedSet) calls with setAds(result.ads) / setAds(cachedSet) directly.

Context Used: Find ways to simplify the implementation (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: cli/src/hooks/use-gravity-ad.ts
Line: 183-186

Comment:
**`showChoiceAds` is now a trivial wrapper**

After removing `showAd`, `showChoiceAds` is a single-line function wrapping `setAds`. It could be inlined at its two call sites to further reduce indirection.

Then replace the two `showChoiceAds(result.ads)` / `showChoiceAds(cachedSet)` calls with `setAds(result.ads)` / `setAds(cachedSet)` directly.

**Context Used:** Find ways to simplify the implementation ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +56 to +61
function noAdsResponse(provider: AdProviderId) {
return NextResponse.json(
{ ads: [], variant: 'choice', provider },
{ status: 200 },
)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Vestigial variant field in responses

Now that both the CLI hook and the server-side type contract have dropped the banner/choice distinction, variant: 'choice' in noAdsResponse (and in the success/error responses in _post.ts) is never read by any consumer. Dropping it would complete the simplification and keep the wire format consistent with the new FetchAdResult shape.

Suggested change
function noAdsResponse(provider: AdProviderId) {
return NextResponse.json(
{ ads: [], variant: 'choice', provider },
{ status: 200 },
)
}
function noAdsResponse(provider: AdProviderId) {
return NextResponse.json(
{ ads: [], provider },
{ status: 200 },
)
}

Context Used: Find ways to simplify the implementation (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: web/src/app/api/v1/ads/_post.ts
Line: 56-61

Comment:
**Vestigial `variant` field in responses**

Now that both the CLI hook and the server-side type contract have dropped the banner/choice distinction, `variant: 'choice'` in `noAdsResponse` (and in the success/error responses in `_post.ts`) is never read by any consumer. Dropping it would complete the simplification and keep the wire format consistent with the new `FetchAdResult` shape.

```suggestion
function noAdsResponse(provider: AdProviderId) {
  return NextResponse.json(
    { ads: [], provider },
    { status: 200 },
  )
}
```

**Context Used:** Find ways to simplify the implementation ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

How can I resolve this? If you propose a fix, please make it concise.

@jahooma jahooma merged commit 0cdbe01 into main Apr 29, 2026
34 checks passed
@jahooma jahooma deleted the jahooma/check-gravity-ad-id branch April 29, 2026 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant