Skip to content

Commit 09926fc

Browse files
committed
Tweak to model selection design
1 parent bbd09e6 commit 09926fc

2 files changed

Lines changed: 33 additions & 42 deletions

File tree

cli/src/components/freebuff-model-selector.tsx

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
DEFAULT_FREEBUFF_MODEL_ID,
88
FALLBACK_FREEBUFF_MODEL_ID,
99
FREEBUFF_MODELS,
10-
FREEBUFF_PREMIUM_SESSION_LIMIT,
1110
getFreebuffDeploymentAvailabilityLabel,
1211
isFreebuffModelAvailable,
1312
isFreebuffPremiumModelId,
@@ -39,11 +38,12 @@ const FREEBUFF_MODEL_SELECTOR_MODEL_IDS = FREEBUFF_MODEL_SELECTOR_MODELS.map(
3938
(model) => model.id,
4039
)
4140

42-
// Section grouping: premium models share one quota pool (header carries the
43-
// 0/5 counter); the unlimited model has none. Putting the tier on a section
44-
// header lets each row drop its redundant "Premium"/"Unlimited" chip. Empty
45-
// sections are filtered out so a model set with no premium (or no unlimited)
46-
// entries doesn't render an orphan header.
41+
// Section grouping: premium models share one quota pool, unlimited has none.
42+
// Putting the tier on a section header lets each row drop its redundant
43+
// "Premium"/"Unlimited" chip. The shared 0/5 counter lives in the page title
44+
// (rendered by the parent), not the section header — this picker is purely a
45+
// list of choices grouped by tier. Empty sections are filtered so a model set
46+
// with no premium (or no unlimited) entries doesn't render an orphan header.
4747
type Section = {
4848
key: 'premium' | 'unlimited'
4949
label: string
@@ -69,10 +69,6 @@ const SECTIONS: readonly Section[] = (
6969
] satisfies readonly Section[]
7070
).filter((section) => section.models.length > 0)
7171

72-
function formatSessionUnits(units: number): string {
73-
return Number.isInteger(units) ? String(units) : units.toFixed(1)
74-
}
75-
7672
/**
7773
* Dual-purpose model picker:
7874
* - Pre-chat landing (session 'none'): user hasn't joined any queue. Picking
@@ -136,18 +132,6 @@ export const FreebuffModelSelector: React.FC = () => {
136132
? session.rateLimitsByModel
137133
: undefined
138134

139-
// All premium models share one quota pool: the server replicates the same
140-
// snapshot under each premium model id, so any entry has the right count.
141-
// Grab the first one (or 0 when the user has no usage and the map is
142-
// absent) so the section header can render the single shared counter.
143-
const sharedPremiumUsed = useMemo(
144-
() =>
145-
rateLimitsByModel
146-
? (Object.values(rateLimitsByModel)[0]?.recentCount ?? 0)
147-
: 0,
148-
[rateLimitsByModel],
149-
)
150-
151135
const BUTTON_CHROME = 4 // 2 border + 2 padding
152136
const NAME_GAP = 2 // spaces between name column and details column
153137

@@ -366,11 +350,6 @@ export const FreebuffModelSelector: React.FC = () => {
366350
)
367351
}
368352

369-
// Counter goes amber-ish (theme.secondary) when the pool is exhausted so
370-
// the limit reads as "you've hit it" rather than just another count.
371-
const premiumExhausted = sharedPremiumUsed >= FREEBUFF_PREMIUM_SESSION_LIMIT
372-
const counterColor = premiumExhausted ? theme.secondary : theme.muted
373-
374353
return (
375354
<box
376355
style={{
@@ -389,16 +368,7 @@ export const FreebuffModelSelector: React.FC = () => {
389368
marginTop: sectionIdx === 0 ? 0 : 1,
390369
}}
391370
>
392-
<text style={{ wrapMode: 'word' }}>
393-
<span fg={theme.muted}>{section.label}</span>
394-
{section.key === 'premium' && (
395-
<span fg={counterColor}>
396-
{' · '}
397-
{formatSessionUnits(sharedPremiumUsed)} /{' '}
398-
{FREEBUFF_PREMIUM_SESSION_LIMIT} used today
399-
</span>
400-
)}
401-
</text>
371+
<text style={{ fg: theme.muted }}>{section.label}</text>
402372
{section.models.map(renderModelButton)}
403373
</box>
404374
))}

cli/src/components/waiting-room-screen.tsx

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { useTerminalDimensions } from '../hooks/use-terminal-dimensions'
1616
import { useTheme } from '../hooks/use-theme'
1717
import { exitFreebuffCleanly } from '../utils/freebuff-exit'
1818
import { getLogoAccentColor, getLogoBlockColor } from '../utils/theme-system'
19+
import { FREEBUFF_PREMIUM_SESSION_LIMIT } from '@codebuff/common/constants/freebuff-models'
1920

2021
import type { FreebuffSessionResponse } from '../types/freebuff-session'
2122
import type { FreebuffIpPrivacySignal } from '@codebuff/common/types/freebuff-session'
@@ -263,6 +264,23 @@ export const WaitingRoomScreen: React.FC<WaitingRoomScreenProps> = ({
263264
// 'queued' (waiting room) or straight to 'active' (chat) if no wait.
264265
const isLanding = session?.status === 'none'
265266

267+
// Premium quota counter for the title line. All premium models share one
268+
// pool; the server replicates the same snapshot under each premium model
269+
// id, so any entry has the right count. Renders amber when exhausted so
270+
// the limit reads as "you've hit it" rather than just another count.
271+
const rateLimitsByModel =
272+
session && 'rateLimitsByModel' in session
273+
? session.rateLimitsByModel
274+
: undefined
275+
const sharedPremiumUsed = rateLimitsByModel
276+
? (Object.values(rateLimitsByModel)[0]?.recentCount ?? 0)
277+
: 0
278+
const premiumLeft = Math.max(
279+
0,
280+
FREEBUFF_PREMIUM_SESSION_LIMIT - sharedPremiumUsed,
281+
)
282+
const premiumLeftColor = premiumLeft === 0 ? theme.secondary : theme.muted
283+
266284
return (
267285
<box
268286
style={{
@@ -344,11 +362,14 @@ export const WaitingRoomScreen: React.FC<WaitingRoomScreenProps> = ({
344362
gap: 0,
345363
}}
346364
>
347-
<text
348-
style={{ fg: theme.foreground, marginBottom: 1 }}
349-
attributes={TextAttributes.BOLD}
350-
>
351-
Pick a model to start
365+
<text style={{ marginBottom: 1, wrapMode: 'word' }}>
366+
<span fg={theme.foreground} attributes={TextAttributes.BOLD}>
367+
Pick a model to start
368+
</span>
369+
<span fg={premiumLeftColor}>
370+
{' · '}
371+
{premiumLeft} premium left today
372+
</span>
352373
</text>
353374
<FreebuffModelSelector />
354375
</box>

0 commit comments

Comments
 (0)