/** * @license * Copyright 2025 Vybestack LLC * SPDX-License-Identifier: Apache-2.0 */ import type React from 'react'; import { createContext, useContext } from 'react'; import type { IdeIntegrationNudgeResult } from '../IdeIntegrationNudge.js'; import type { HistoryItem } from '../types.js'; import type { FolderTrustChoice } from '../components/FolderTrustDialog.js'; import type { Key } from '../hooks/useKeypress.js'; import type { EditorType } from '@vybestack/llxprt-code-core'; import type { SettingScope } from '../../config/settings.js'; import type { SubagentView } from '../components/SubagentManagement/types.js'; /** * UI Actions shape for the AppContainer architecture. * This consolidates all UI actions/callbacks that were previously * scattered across the monolithic App.tsx component. */ export interface UIActions { // History actions addItem: (item: Omit, timestamp?: number) => number; clearItems: () => void; loadHistory: (newHistory: HistoryItem[]) => void; refreshStatic: () => void; // Input actions handleUserInputSubmit: (value: string) => void; handleSteer: (text: string) => boolean; handleClearScreen: () => void; // Theme dialog openThemeDialog: () => void; handleThemeSelect: ( themeName: string | undefined, scope: SettingScope, ) => void; handleThemeHighlight: (themeName: string | undefined) => void; // Settings dialog openSettingsDialog: () => void; closeSettingsDialog: () => void; handleSettingsRestart: () => void; // Auth dialog openAuthDialog: () => void; handleAuthSelect: ( method: string | undefined, scope: SettingScope, ) => Promise; handleAuthTimeout: () => void; // Editor dialog openEditorDialog: () => void; handleEditorSelect: ( editorType: EditorType | undefined, scope: SettingScope, ) => void; exitEditorDialog: () => void; // Provider dialog openProviderDialog: () => void; handleProviderSelect: (provider: string) => Promise; exitProviderDialog: () => void; // Load profile dialog openLoadProfileDialog: () => void; handleProfileSelect: (profile: string) => void; exitLoadProfileDialog: () => void; // Create profile dialog openCreateProfileDialog: () => void; exitCreateProfileDialog: () => void; // Profile management dialogs openProfileListDialog: () => void; closeProfileListDialog: () => void; viewProfileDetail: (profileName: string, openedDirectly?: boolean) => void; closeProfileDetailDialog: () => void; loadProfileFromDetail: (profileName: string) => void; deleteProfileFromDetail: (profileName: string) => void; deleteProfileFromList: (profileName: string) => void; setProfileAsDefault: (profileName: string) => void; openProfileEditor: (profileName: string, openedDirectly?: boolean) => void; closeProfileEditor: () => void; saveProfileFromEditor: ( profileName: string, updatedProfile: unknown, ) => Promise; // Tools dialog openToolsDialog: (action: 'enable' | 'disable') => void; handleToolsSelect: (tool: string) => void; exitToolsDialog: () => void; // Folder trust dialog handleFolderTrustSelect: (choice: FolderTrustChoice) => Promise; // Welcome onboarding welcomeActions: { startSetup: () => void; selectProvider: (providerId: string) => void; selectModel: (modelId: string) => void; selectAuthMethod: (method: 'oauth' | 'api_key') => void; onAuthComplete: () => void; onAuthError: (error: string) => void; skipSetup: () => void; goBack: () => void; saveProfile: (name: string) => Promise; dismiss: () => void; resetAndReopen: () => void; }; triggerWelcomeAuth: ( provider: string, method: 'oauth' | 'api_key', apiKey?: string, ) => Promise; // Permissions dialog openPermissionsDialog: () => void; closePermissionsDialog: () => void; // Logging dialog openLoggingDialog: (data?: { entries: unknown[] }) => void; closeLoggingDialog: () => void; // Subagent dialog openSubagentDialog: ( initialView?: SubagentView, initialName?: string, ) => void; closeSubagentDialog: () => void; // Models dialog openModelsDialog: (data?: { initialSearch?: string; initialFilters?: { tools?: boolean; vision?: boolean; reasoning?: boolean; audio?: boolean; }; includeDeprecated?: boolean; }) => void; closeModelsDialog: () => void; // Model config dialog openModelConfigDialog: () => void; closeModelConfigDialog: () => void; // Policies dialog openPoliciesDialog: () => void; closePoliciesDialog: () => void; /** * Session browser dialog * @plan PLAN-20260214-SESSIONBROWSER.P21 */ openSessionBrowserDialog: () => void; closeSessionBrowserDialog: () => void; // Workspace migration dialog onWorkspaceMigrationDialogOpen: () => void; onWorkspaceMigrationDialogClose: () => void; // Privacy notice openPrivacyNotice: () => void; handlePrivacyNoticeExit: () => void; // OAuth code dialog handleOAuthCodeDialogClose: () => void; handleOAuthCodeSubmit: (code: string) => Promise; // Confirmation handlers handleConfirmationSelect: (value: boolean) => void; // IDE prompt handleIdePromptComplete: (result: IdeIntegrationNudgeResult) => void; // Vim vimHandleInput: (key: Key) => boolean; toggleVimEnabled: () => void; // Slash commands handleSlashCommand: (command: string) => void; // Memory performMemoryRefresh: () => Promise; // Display toggles setShowErrorDetails: (show: boolean) => void; setShowToolDescriptions: (show: boolean) => void; setConstrainHeight: (constrain: boolean) => void; // Shell mode setShellModeActive: (active: boolean) => void; // Escape prompt handleEscapePromptChange: (show: boolean) => void; // Cancel ongoing request cancelOngoingRequest?: () => void; // Queue error message setQueueErrorMessage: (message: string | null) => void; // Queued messages actions (issue #2882) sendAllQueuedSubmissions?: () => void; steerAllQueuedSubmissions?: () => void; clearQueuedSubmissions?: () => void; } const UIActionsContext = createContext(undefined); export function UIActionsProvider({ children, value, }: { children: React.ReactNode; value: UIActions; }) { return ( {children} ); } export function useUIActions(): UIActions { const context = useContext(UIActionsContext); if (!context) { throw new Error('useUIActions must be used within a UIActionsProvider'); } return context; } export { UIActionsContext };