MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / shouldAutoShowBanner

Function shouldAutoShowBanner

cli/src/utils/usage-banner-state.ts:98–146  ·  view source on GitHub ↗
(
  isChainInProgress: boolean,
  hasAuthToken: boolean,
  remainingBalance: number | null,
  lastWarnedThreshold: number | null,
  autoTopupEnabled: boolean = false,
)

Source from the content-addressed store, hash-verified

96 * - User does NOT have auto top-up enabled (unless truly out of credits <= 0)
97 */
98export function shouldAutoShowBanner(
99 isChainInProgress: boolean,
100 hasAuthToken: boolean,
101 remainingBalance: number | null,
102 lastWarnedThreshold: number | null,
103 autoTopupEnabled: boolean = false,
104): AutoShowDecision {
105 // Don't show during active chains
106 if (isChainInProgress) {
107 return { shouldShow: false, newWarningThreshold: lastWarnedThreshold }
108 }
109
110 // Don't show for unauthenticated users
111 if (!hasAuthToken) {
112 return { shouldShow: false, newWarningThreshold: lastWarnedThreshold }
113 }
114
115 // Don't show if we don't have balance data
116 if (remainingBalance === null) {
117 return { shouldShow: false, newWarningThreshold: lastWarnedThreshold }
118 }
119
120 // For users with auto top-up enabled, only show if truly out of credits (<= 0)
121 // Auto top-up users want to "set and forget" - don't bother them with threshold warnings
122 if (autoTopupEnabled && remainingBalance > 0) {
123 return { shouldShow: false, newWarningThreshold: null }
124 }
125
126 const currentThreshold = getThresholdTier(remainingBalance)
127
128 // Clear warning state if user is back above all thresholds
129 if (currentThreshold === null) {
130 return { shouldShow: false, newWarningThreshold: null }
131 }
132
133 // Show banner if we've crossed a new threshold we haven't warned about
134 // A "new" threshold means either:
135 // 1. We haven't warned about any threshold yet (lastWarnedThreshold === null)
136 // 2. The current threshold is lower than what we last warned about
137 const isNewThreshold =
138 lastWarnedThreshold === null || currentThreshold < lastWarnedThreshold
139
140 if (isNewThreshold) {
141 return { shouldShow: true, newWarningThreshold: currentThreshold }
142 }
143
144 // Already warned about this threshold
145 return { shouldShow: false, newWarningThreshold: lastWarnedThreshold }
146}

Callers 2

useUsageMonitorFunction · 0.90

Calls 1

getThresholdTierFunction · 0.85

Tested by

no test coverage detected