-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathUIStateContext.tsx
More file actions
230 lines (224 loc) · 7.88 KB
/
Copy pathUIStateContext.tsx
File metadata and controls
230 lines (224 loc) · 7.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { createContext, useContext } from 'react';
import type {
HistoryItem,
HistoryItemBtw,
ThoughtSummary,
ShellConfirmationRequest,
ConfirmationRequest,
LoopDetectionConfirmationRequest,
HistoryItemWithoutId,
StreamingState,
SettingInputRequest,
PluginChoiceRequest,
} from '../types.js';
import type { TodoItem } from '../components/TodoDisplay.js';
import type { AuthUiState } from '../auth/useAuth.js';
import type { CommandContext, SlashCommand } from '../commands/types.js';
import type { RecentSlashCommands } from '../hooks/useSlashCompletion.js';
import type { TextBuffer } from '../components/shared/text-buffer.js';
import type {
IdeContext,
ApprovalMode,
IdeInfo,
SessionListItem,
} from '@qwen-code/qwen-code-core';
import type { DOMElement } from 'ink';
import type { SessionStatsState } from '../contexts/SessionContext.js';
import type { PendingMcpServer } from '../hooks/useMcpApproval.js';
import type { ExtensionUpdateState } from '../state/extensions.js';
import type { UpdateObject } from '../utils/updateCheck.js';
import { type UseHistoryManagerReturn } from '../hooks/useHistoryManager.js';
import { type HelpTab } from './UIActionsContext.js';
import { type RestartReason } from '../hooks/useIdeTrustListener.js';
import { type ProviderUpdateRequest } from '../hooks/useProviderUpdates.js';
import { type ArenaDialogType } from '../hooks/useArenaCommand.js';
import type { StatusLinePresetConfig } from '../statusLinePresets.js';
export interface PendingSkillView {
name: string;
description: string;
}
export interface UIState {
history: HistoryItem[];
historyManager: UseHistoryManagerReturn;
isThemeDialogOpen: boolean;
themeError: string | null;
auth: AuthUiState;
isConfigInitialized: boolean;
editorError: string | null;
isEditorDialogOpen: boolean;
debugMessage: string;
quittingMessages: HistoryItem[] | null;
isSettingsDialogOpen: boolean;
isStatusLineDialogOpen: boolean;
statusLineSettingsVersion?: number;
statusLineConfigOverride?: StatusLinePresetConfig;
isMemoryDialogOpen: boolean;
isSkillReviewDialogOpen: boolean;
/** Pending auto-skills awaiting confirmation, plus their owning task id. */
skillReviewPending: { taskId: string; skills: PendingSkillView[] } | null;
isModelDialogOpen: boolean;
isFastModelMode: boolean;
isVoiceModelMode: boolean;
isVisionModelMode: boolean;
isCompactionModelMode: boolean;
isTrustDialogOpen: boolean;
activeArenaDialog: ArenaDialogType;
isPermissionsDialogOpen: boolean;
isApprovalModeDialogOpen: boolean;
isEffortDialogOpen: boolean;
isResumeDialogOpen: boolean;
resumeMatchedSessions: SessionListItem[] | undefined;
isDeleteDialogOpen: boolean;
isHelpDialogOpen: boolean;
activeHelpTab: HelpTab;
slashCommands: readonly SlashCommand[];
recentSlashCommands: RecentSlashCommands;
pendingSlashCommandHistoryItems: HistoryItemWithoutId[];
commandContext: CommandContext;
shellConfirmationRequest: ShellConfirmationRequest | null;
confirmationRequest: ConfirmationRequest | null;
confirmUpdateExtensionRequests: ConfirmationRequest[];
providerUpdateRequest: ProviderUpdateRequest | undefined;
settingInputRequests: SettingInputRequest[];
pluginChoiceRequests: PluginChoiceRequest[];
loopDetectionConfirmationRequest: LoopDetectionConfirmationRequest | null;
geminiMdFileCount: number;
streamingState: StreamingState;
initError: string | null;
pendingGeminiHistoryItems: HistoryItemWithoutId[];
thought: ThoughtSummary | null;
shellModeActive: boolean;
userMessages: string[];
buffer: TextBuffer;
inputWidth: number;
suggestionsWidth: number;
isInputActive: boolean;
shouldShowIdePrompt: boolean;
shouldShowCommandMigrationNudge: boolean;
commandMigrationTomlFiles: string[];
isFolderTrustDialogOpen: boolean;
isMcpApprovalDialogOpen: boolean;
currentMcpApproval: PendingMcpServer | undefined;
pendingMcpApprovals: PendingMcpServer[];
mcpApprovalRemaining: number;
isTrustedFolder: boolean | undefined;
constrainHeight: boolean;
ideContextState: IdeContext | undefined;
showToolDescriptions: boolean;
ctrlCPressedOnce: boolean;
ctrlDPressedOnce: boolean;
showEscapePrompt: boolean;
elapsedTime: number;
currentLoadingPhrase: string;
historyRemountKey: number;
messageQueue: string[];
showAutoAcceptIndicator: ApprovalMode;
// Quota-related state
currentModel: string;
contextFileNames: string[];
availableTerminalHeight: number | undefined;
useTerminalBuffer: boolean;
mainAreaWidth: number;
staticAreaMaxItemHeight: number;
staticExtraHeight: number;
dialogsVisible: boolean;
pendingHistoryItems: HistoryItemWithoutId[];
stickyTodos: TodoItem[] | null;
btwItem: HistoryItemBtw | null;
setBtwItem: (item: HistoryItemBtw | null) => void;
cancelBtw: () => void;
nightly: boolean;
branchName: string | undefined;
/**
* Active worktree session (from the `<sessionId>.worktree.json` sidecar).
* Set when `enter_worktree` has been called, cleared when `exit_worktree`
* removes the sidecar. Used by the Footer to display the worktree
* indicator and by WorktreeExitDialog to know what to operate on.
*/
activeWorktree: {
slug: string;
branch: string;
path: string;
originalCwd: string;
originalBranch: string;
originalHeadCommit: string;
} | null;
/** Visibility of WorktreeExitDialog (only shown when activeWorktree != null). */
showWorktreeExitDialog: boolean;
/**
* P7-trigger: true while the current turn was steered toward the Workflow
* tool by the `workflow` keyword. Drives the Footer `workflow active`
* indicator; cleared when the turn returns to idle.
*/
workflowKeywordActive: boolean;
sessionStats: SessionStatsState;
terminalWidth: number;
terminalHeight: number;
mainControlsRef: React.MutableRefObject<DOMElement | null>;
currentIDE: IdeInfo | null;
updateInfo: UpdateObject | null;
showIdeRestartPrompt: boolean;
ideTrustRestartReason: RestartReason;
isRestarting: boolean;
extensionsUpdateState: Map<string, ExtensionUpdateState>;
activePtyId: number | undefined;
embeddedShellFocused: boolean;
// Welcome back dialog
showWelcomeBackDialog: boolean;
welcomeBackInfo: {
hasHistory: boolean;
lastPrompt?: string;
} | null;
welcomeBackChoice: 'continue' | 'restart' | null;
// Subagent dialogs
isSubagentCreateDialogOpen: boolean;
isAgentsManagerDialogOpen: boolean;
// Skills manager dialog (`/skills`)
isSkillsManagerDialogOpen: boolean;
// Extensions manager dialog
isExtensionsManagerDialogOpen: boolean;
// MCP dialog
isMcpDialogOpen: boolean;
// Hooks dialog
isHooksDialogOpen: boolean;
isStatsDialogOpen: boolean;
// Feedback dialog
isFeedbackDialogOpen: boolean;
// Per-task token tracking
taskStartTokens: number;
taskStartStreamingChars: number;
responseCandidateTokens: number;
// Real-time token display: ref to streaming output char length (polled, not state)
streamingResponseLengthRef: React.RefObject<number>;
// True = receiving content (↓), false = waiting for API response (↑)
isReceivingContent: boolean;
// Session custom name (set via /rename)
sessionName: string | null;
setSessionName: (name: string | null) => void;
// Prompt suggestion
promptSuggestion: string | null;
/**
* Abort in-flight suggestion generation/speculation; intentionally preserves
* `promptSuggestion` so the placeholder can restore it when the buffer is
* emptied again.
*/
abortPromptSuggestion: () => void;
// Rewind selector
isRewindSelectorOpen: boolean;
rewindEscPending: boolean;
// Diff dialog
isDiffDialogOpen: boolean;
}
export const UIStateContext = createContext<UIState | null>(null);
export const useUIState = () => {
const context = useContext(UIStateContext);
if (!context) {
throw new Error('useUIState must be used within a UIStateProvider');
}
return context;
};