Skip to content

Commit 4ac8d9a

Browse files
committed
refactor(cli): consolidate banner state into input mode system
Replace isUsageVisible boolean with inputMode state management. Add "usage" mode to InputMode type and update all references. Simplifies state by using single inputMode instead of separate visibility flags.
1 parent 8064e5e commit 4ac8d9a

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

cli/src/commands/usage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function handleUsageCommand(): Promise<{
1919

2020
// Show the usage banner - the useUsageQuery hook will automatically fetch
2121
// the data when the banner becomes visible
22-
useChatStore.getState().setIsUsageVisible(true)
22+
useChatStore.getState().setInputMode('usage')
2323

2424
const postUserMessage: PostUserMessageFn = (prev) => prev
2525
return { postUserMessage }

cli/src/state/chat-store.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import { immer } from 'zustand/middleware/immer'
55
import { clamp } from '../utils/math'
66
import { loadModePreference, saveModePreference } from '../utils/settings'
77

8-
import type { InputMode } from '../utils/input-modes'
9-
108
import type { ChatMessage } from '../types/chat'
119
import type { AgentMode } from '../utils/constants'
10+
import type { InputMode } from '../utils/input-modes'
1211
import type { RunState } from '@codebuff/sdk'
1312

1413
export type InputValue = {
@@ -35,7 +34,6 @@ export type ChatStoreState = {
3534
lastMessageMode: AgentMode | null
3635
sessionCreditsUsed: number
3736
runState: RunState | null
38-
isUsageVisible: boolean
3937
isAnnouncementVisible: boolean
4038
inputMode: InputMode
4139
isRetrying: boolean
@@ -68,7 +66,6 @@ type ChatStoreActions = {
6866
setLastMessageMode: (mode: AgentMode | null) => void
6967
addSessionCredits: (credits: number) => void
7068
setRunState: (runState: RunState | null) => void
71-
setIsUsageVisible: (visible: boolean) => void
7269
setIsAnnouncementVisible: (visible: boolean) => void
7370
setInputMode: (mode: InputMode) => void
7471
setIsRetrying: (retrying: boolean) => void
@@ -95,7 +92,6 @@ const initialState: ChatStoreState = {
9592
lastMessageMode: null,
9693
sessionCreditsUsed: 0,
9794
runState: null,
98-
isUsageVisible: false,
9995
isAnnouncementVisible: true,
10096
inputMode: 'default' as InputMode,
10197
isRetrying: false,
@@ -209,11 +205,6 @@ export const useChatStore = create<ChatStore>()(
209205
state.runState = runState ? castDraft(runState) : null
210206
}),
211207

212-
setIsUsageVisible: (visible) =>
213-
set((state) => {
214-
state.isUsageVisible = visible
215-
}),
216-
217208
setIsAnnouncementVisible: (visible) =>
218209
set((state) => {
219210
state.isAnnouncementVisible = visible
@@ -250,7 +241,6 @@ export const useChatStore = create<ChatStore>()(
250241
state.runState = initialState.runState
251242
? castDraft(initialState.runState)
252243
: null
253-
state.isUsageVisible = initialState.isUsageVisible
254244
state.isAnnouncementVisible = initialState.isAnnouncementVisible
255245
state.inputMode = initialState.inputMode
256246
state.isRetrying = initialState.isRetrying

cli/src/utils/fetch-usage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface FetchAndUpdateUsageParams {
1919
getAuthToken?: () => string | undefined
2020
getChatStore?: () => {
2121
sessionCreditsUsed: number
22-
setIsUsageVisible: (visible: boolean) => void
22+
setInputMode: (mode: 'usage' | 'default') => void
2323
}
2424
logger?: Logger
2525
fetch?: typeof globalThis.fetch
@@ -77,7 +77,7 @@ export async function fetchAndUpdateUsage(
7777
// We no longer update the store here since usage data is managed by TanStack Query.
7878

7979
if (showBanner) {
80-
chatStore.setIsUsageVisible(true)
80+
chatStore.setInputMode('usage')
8181
}
8282

8383
return true

cli/src/utils/input-modes.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// 1. Add it to the InputMode type
44
// 2. Add its configuration to INPUT_MODE_CONFIGS
55

6-
export type InputMode = 'default' | 'bash' | 'referral'
6+
export type InputMode = 'default' | 'bash' | 'referral' | 'usage'
77

88
// Theme color keys that are valid color values (must match ChatTheme keys)
99
export type ThemeColorKey = 'foreground' | 'background' | 'error' | 'warning' | 'success' | 'info' | 'muted'
@@ -48,6 +48,14 @@ export const INPUT_MODE_CONFIGS: Record<InputMode, InputModeConfig> = {
4848
showAgentModeToggle: false,
4949
disableSlashSuggestions: true,
5050
},
51+
usage: {
52+
icon: null,
53+
color: 'foreground',
54+
placeholder: 'type a message...',
55+
widthAdjustment: 0,
56+
showAgentModeToggle: true,
57+
disableSlashSuggestions: false,
58+
},
5159
}
5260

5361
export function getInputModeConfig(mode: InputMode): InputModeConfig {

0 commit comments

Comments
 (0)