Cleanup: Remove low value StreamingContextType interface. (#585)

This commit is contained in:
Jacob Richman 2025-05-28 19:46:08 +00:00 committed by GitHub
parent 05a49702d8
commit 00805cb2cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 15 additions and 41 deletions

View File

@ -41,10 +41,7 @@ import { useHistory } from './hooks/useHistoryManager.js';
import process from 'node:process'; import process from 'node:process';
import { getErrorMessage, type Config } from '@gemini-code/server'; import { getErrorMessage, type Config } from '@gemini-code/server';
import { useLogger } from './hooks/useLogger.js'; import { useLogger } from './hooks/useLogger.js';
import { import { StreamingContext } from './contexts/StreamingContext.js';
StreamingContext,
StreamingContextType,
} from './contexts/StreamingContext.js';
interface AppProps { interface AppProps {
config: Config; config: Config;
@ -182,11 +179,6 @@ export const App = ({
useLoadingIndicator(streamingState); useLoadingIndicator(streamingState);
const showAutoAcceptIndicator = useAutoAcceptIndicator({ config }); const showAutoAcceptIndicator = useAutoAcceptIndicator({ config });
const streamingContextValue: StreamingContextType = useMemo(
() => ({ streamingState }),
[streamingState],
);
const handleFinalSubmit = useCallback( const handleFinalSubmit = useCallback(
(submittedValue: string) => { (submittedValue: string) => {
const trimmedValue = submittedValue.trim(); const trimmedValue = submittedValue.trim();
@ -278,7 +270,7 @@ export const App = ({
}, [consoleMessages, config]); }, [consoleMessages, config]);
return ( return (
<StreamingContext.Provider value={streamingContextValue}> <StreamingContext.Provider value={streamingState}>
<Box flexDirection="column" marginBottom={1} width="90%"> <Box flexDirection="column" marginBottom={1} width="90%">
{/* {/*
* The Static component is an Ink intrinsic in which there can only be 1 per application. * The Static component is an Ink intrinsic in which there can only be 1 per application.

View File

@ -23,7 +23,7 @@ interface GeminiRespondingSpinnerProps {
export const GeminiRespondingSpinner: React.FC< export const GeminiRespondingSpinner: React.FC<
GeminiRespondingSpinnerProps GeminiRespondingSpinnerProps
> = ({ nonRespondingDisplay, spinnerType = 'dots' }) => { > = ({ nonRespondingDisplay, spinnerType = 'dots' }) => {
const { streamingState } = useStreamingContext(); const streamingState = useStreamingContext();
if (streamingState === StreamingState.Responding) { if (streamingState === StreamingState.Responding) {
return <Spinner type={spinnerType} />; return <Spinner type={spinnerType} />;

View File

@ -8,10 +8,7 @@ import React from 'react';
import { render } from 'ink-testing-library'; import { render } from 'ink-testing-library';
import { Text } from 'ink'; import { Text } from 'ink';
import { LoadingIndicator } from './LoadingIndicator.js'; import { LoadingIndicator } from './LoadingIndicator.js';
import { import { StreamingContext } from '../contexts/StreamingContext.js';
StreamingContext,
StreamingContextType,
} from '../contexts/StreamingContext.js';
import { StreamingState } from '../types.js'; import { StreamingState } from '../types.js';
import { vi } from 'vitest'; import { vi } from 'vitest';
@ -22,7 +19,7 @@ vi.mock('./GeminiRespondingSpinner.js', () => ({
}: { }: {
nonRespondingDisplay?: string; nonRespondingDisplay?: string;
}) => { }) => {
const { streamingState } = React.useContext(StreamingContext)!; const streamingState = React.useContext(StreamingContext)!;
if (streamingState === StreamingState.Responding) { if (streamingState === StreamingState.Responding) {
return <Text>MockRespondingSpinner</Text>; return <Text>MockRespondingSpinner</Text>;
} else if (nonRespondingDisplay) { } else if (nonRespondingDisplay) {
@ -36,9 +33,7 @@ const renderWithContext = (
ui: React.ReactElement, ui: React.ReactElement,
streamingStateValue: StreamingState, streamingStateValue: StreamingState,
) => { ) => {
const contextValue: StreamingContextType = { const contextValue: StreamingState = streamingStateValue;
streamingState: streamingStateValue,
};
return render( return render(
<StreamingContext.Provider value={contextValue}> <StreamingContext.Provider value={contextValue}>
{ui} {ui}
@ -129,9 +124,7 @@ describe('<LoadingIndicator />', () => {
// Transition to Responding // Transition to Responding
rerender( rerender(
<StreamingContext.Provider <StreamingContext.Provider value={StreamingState.Responding}>
value={{ streamingState: StreamingState.Responding }}
>
<LoadingIndicator <LoadingIndicator
currentLoadingPhrase="Now Responding" currentLoadingPhrase="Now Responding"
elapsedTime={2} elapsedTime={2}
@ -145,9 +138,7 @@ describe('<LoadingIndicator />', () => {
// Transition to WaitingForConfirmation // Transition to WaitingForConfirmation
rerender( rerender(
<StreamingContext.Provider <StreamingContext.Provider value={StreamingState.WaitingForConfirmation}>
value={{ streamingState: StreamingState.WaitingForConfirmation }}
>
<LoadingIndicator <LoadingIndicator
currentLoadingPhrase="Please Confirm" currentLoadingPhrase="Please Confirm"
elapsedTime={15} elapsedTime={15}
@ -162,9 +153,7 @@ describe('<LoadingIndicator />', () => {
// Transition back to Idle // Transition back to Idle
rerender( rerender(
<StreamingContext.Provider <StreamingContext.Provider value={StreamingState.Idle}>
value={{ streamingState: StreamingState.Idle }}
>
<LoadingIndicator {...defaultProps} /> <LoadingIndicator {...defaultProps} />
</StreamingContext.Provider>, </StreamingContext.Provider>,
); );

View File

@ -22,7 +22,7 @@ export const LoadingIndicator: React.FC<LoadingIndicatorProps> = ({
elapsedTime, elapsedTime,
rightContent, rightContent,
}) => { }) => {
const { streamingState } = useStreamingContext(); const streamingState = useStreamingContext();
if (streamingState === StreamingState.Idle) { if (streamingState === StreamingState.Idle) {
return null; return null;

View File

@ -9,10 +9,7 @@ import { render } from 'ink-testing-library';
import { ToolMessage, ToolMessageProps } from './ToolMessage.js'; import { ToolMessage, ToolMessageProps } from './ToolMessage.js';
import { StreamingState, ToolCallStatus } from '../../types.js'; import { StreamingState, ToolCallStatus } from '../../types.js';
import { Text } from 'ink'; import { Text } from 'ink';
import { import { StreamingContext } from '../../contexts/StreamingContext.js';
StreamingContext,
StreamingContextType,
} from '../../contexts/StreamingContext.js';
// Mock child components or utilities if they are complex or have side effects // Mock child components or utilities if they are complex or have side effects
vi.mock('../GeminiRespondingSpinner.js', () => ({ vi.mock('../GeminiRespondingSpinner.js', () => ({
@ -21,7 +18,7 @@ vi.mock('../GeminiRespondingSpinner.js', () => ({
}: { }: {
nonRespondingDisplay?: string; nonRespondingDisplay?: string;
}) => { }) => {
const { streamingState } = React.useContext(StreamingContext)!; const streamingState = React.useContext(StreamingContext)!;
if (streamingState === StreamingState.Responding) { if (streamingState === StreamingState.Responding) {
return <Text>MockRespondingSpinner</Text>; return <Text>MockRespondingSpinner</Text>;
} }
@ -48,7 +45,7 @@ const renderWithContext = (
ui: React.ReactElement, ui: React.ReactElement,
streamingState: StreamingState, streamingState: StreamingState,
) => { ) => {
const contextValue: StreamingContextType = { streamingState }; const contextValue: StreamingState = streamingState;
return render( return render(
<StreamingContext.Provider value={contextValue}> <StreamingContext.Provider value={contextValue}>
{ui} {ui}

View File

@ -7,15 +7,11 @@
import React, { createContext } from 'react'; import React, { createContext } from 'react';
import { StreamingState } from '../types.js'; import { StreamingState } from '../types.js';
export interface StreamingContextType { export const StreamingContext = createContext<StreamingState | undefined>(
streamingState: StreamingState;
}
export const StreamingContext = createContext<StreamingContextType | undefined>(
undefined, undefined,
); );
export const useStreamingContext = (): StreamingContextType => { export const useStreamingContext = (): StreamingState => {
const context = React.useContext(StreamingContext); const context = React.useContext(StreamingContext);
if (context === undefined) { if (context === undefined) {
throw new Error( throw new Error(