Skip to content

feat(#456): show "Set up" badge on Agent nav item when Anthropic key is missing - #472

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
Maqbool61:fix/456-agent-nav-setup-badge
Jul 18, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
Maqbool61:fix/456-agent-nav-setup-badge

Conversation

@Maqbool61

@Maqbool61 Maqbool61 commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

PR Description

Problem

On cloud, the Agent sidebar entry works only after an admin saves the org's Anthropic API key in Settings. Until then, clicking it lands on the "Add your Anthropic API key" CTA — the item reads as a broken/dead entry rather than a feature awaiting one-time setup.

Closes #456

Solution

Show a small "Set up" badge on the Agent nav item while the org has no Anthropic key configured (cloud only — self-host uses an env var and doesn't need this).

The key status is probed via GET /api/settings/anthropic-key — the same endpoint the agent page already uses. A module-level cache ensures at most one network request per page load regardless of how many components consume the hook (sidebar + mobile nav mount simultaneously on resize boundaries).

Changes

web/src/hooks/use-agent-key-status.ts (new)

  • Probes /api/settings/anthropic-key once per session via a module-level promise + result cache
  • useAgentKeyStatus(false) (self-host) returns 'configured' immediately — zero network calls
  • Cache resets on full page reload, satisfying the "no realtime requirement" acceptance criterion

web/src/components/layout/sidebar.tsx

  • Calls useAgentKeyStatus(isCloud) and derives agentKeyMissing
  • Computes effectiveBadge: 'Set up' on the Agent item when key is missing, otherwise falls back to item.badge (no change for any other nav item)
  • Expanded: renders a <Badge variant="secondary"> after the label
  • Collapsed: appends (Set up) to the icon tooltip so the hint is still accessible

web/src/components/layout/mobile-nav.tsx

  • Same useAgentKeyStatus + effectiveBadge pattern
  • Badge right-aligns using flex-1 on the label span, matching the existing locked-item layout

Acceptance Criteria

Cloud org without a saved key → Agent item shows "Set up" badge ✅
Clicking still lands on the existing Settings CTA ✅
Key saved → badge gone on next page load ✅
Self-host → no badge, no new network calls ✅
No layout shift for other nav items ✅
Collapsed sidebar mode intact (tooltip updated) ✅
Mobile nav shows the badge too ✅

Testing

CI checks from web/:

yarn lint          # 0 errors
yarn typecheck     # clean
yarn format:check  # all files pass

@gkhngyk
gkhngyk merged commit c94adbe into ansvisor:main Jul 18, 2026
4 checks passed
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.

Sidebar: show a "Set up" badge on the Agent item while the API key isn't configured

2 participants