summaryrefslogtreecommitdiff
path: root/packages/cli/src
diff options
context:
space:
mode:
authorJacob Richman <[email protected]>2025-05-28 19:46:08 +0000
committerGitHub <[email protected]>2025-05-28 12:46:08 -0700
commit00805cb2cdd9786451b9a3a6746f11f47535288d (patch)
treed8cfed9d765c826805fb839e37c2d08b42446e2b /packages/cli/src
parent05a49702d888bee912682f78c3993d98f7f9d628 (diff)
Cleanup: Remove low value StreamingContextType interface. (#585)
Diffstat (limited to 'packages/cli/src')
-rw-r--r--packages/cli/src/ui/App.tsx12
-rw-r--r--packages/cli/src/ui/components/GeminiRespondingSpinner.tsx2
-rw-r--r--packages/cli/src/ui/components/LoadingIndicator.test.tsx23
-rw-r--r--packages/cli/src/ui/components/LoadingIndicator.tsx2
-rw-r--r--packages/cli/src/ui/components/messages/ToolMessage.test.tsx9
-rw-r--r--packages/cli/src/ui/contexts/StreamingContext.tsx8
6 files changed, 15 insertions, 41 deletions
diff --git a/packages/cli/src/ui/App.tsx b/packages/cli/src/ui/App.tsx
index 727450c0..ac508fbf 100644
--- a/packages/cli/src/ui/App.tsx
+++ b/packages/cli/src/ui/App.tsx
@@ -41,10 +41,7 @@ import { useHistory } from './hooks/useHistoryManager.js';
import process from 'node:process';
import { getErrorMessage, type Config } from '@gemini-code/server';
import { useLogger } from './hooks/useLogger.js';
-import {
- StreamingContext,
- StreamingContextType,
-} from './contexts/StreamingContext.js';
+import { StreamingContext } from './contexts/StreamingContext.js';
interface AppProps {
config: Config;
@@ -182,11 +179,6 @@ export const App = ({
useLoadingIndicator(streamingState);
const showAutoAcceptIndicator = useAutoAcceptIndicator({ config });
- const streamingContextValue: StreamingContextType = useMemo(
- () => ({ streamingState }),
- [streamingState],
- );
-
const handleFinalSubmit = useCallback(
(submittedValue: string) => {
const trimmedValue = submittedValue.trim();
@@ -278,7 +270,7 @@ export const App = ({
}, [consoleMessages, config]);
return (
- <StreamingContext.Provider value={streamingContextValue}>
+ <StreamingContext.Provider value={streamingState}>
<Box flexDirection="column" marginBottom={1} width="90%">
{/*
* The Static component is an Ink intrinsic in which there can only be 1 per application.
diff --git a/packages/cli/src/ui/components/GeminiRespondingSpinner.tsx b/packages/cli/src/ui/components/GeminiRespondingSpinner.tsx
index 57f5dd30..97e10cb3 100644
--- a/packages/cli/src/ui/components/GeminiRespondingSpinner.tsx
+++ b/packages/cli/src/ui/components/GeminiRespondingSpinner.tsx
@@ -23,7 +23,7 @@ interface GeminiRespondingSpinnerProps {
export const GeminiRespondingSpinner: React.FC<
GeminiRespondingSpinnerProps
> = ({ nonRespondingDisplay, spinnerType = 'dots' }) => {
- const { streamingState } = useStreamingContext();
+ const streamingState = useStreamingContext();
if (streamingState === StreamingState.Responding) {
return <Spinner type={spinnerType} />;
diff --git a/packages/cli/src/ui/components/LoadingIndicator.test.tsx b/packages/cli/src/ui/components/LoadingIndicator.test.tsx
index c74003e4..3d31818b 100644
--- a/packages/cli/src/ui/components/LoadingIndicator.test.tsx
+++ b/packages/cli/src/ui/components/LoadingIndicator.test.tsx
@@ -8,10 +8,7 @@ import React from 'react';
import { render } from 'ink-testing-library';
import { Text } from 'ink';
import { LoadingIndicator } from './LoadingIndicator.js';
-import {
- StreamingContext,
- StreamingContextType,
-} from '../contexts/StreamingContext.js';
+import { StreamingContext } from '../contexts/StreamingContext.js';
import { StreamingState } from '../types.js';
import { vi } from 'vitest';
@@ -22,7 +19,7 @@ vi.mock('./GeminiRespondingSpinner.js', () => ({
}: {
nonRespondingDisplay?: string;
}) => {
- const { streamingState } = React.useContext(StreamingContext)!;
+ const streamingState = React.useContext(StreamingContext)!;
if (streamingState === StreamingState.Responding) {
return <Text>MockRespondingSpinner</Text>;
} else if (nonRespondingDisplay) {
@@ -36,9 +33,7 @@ const renderWithContext = (
ui: React.ReactElement,
streamingStateValue: StreamingState,
) => {
- const contextValue: StreamingContextType = {
- streamingState: streamingStateValue,
- };
+ const contextValue: StreamingState = streamingStateValue;
return render(
<StreamingContext.Provider value={contextValue}>
{ui}
@@ -129,9 +124,7 @@ describe('<LoadingIndicator />', () => {
// Transition to Responding
rerender(
- <StreamingContext.Provider
- value={{ streamingState: StreamingState.Responding }}
- >
+ <StreamingContext.Provider value={StreamingState.Responding}>
<LoadingIndicator
currentLoadingPhrase="Now Responding"
elapsedTime={2}
@@ -145,9 +138,7 @@ describe('<LoadingIndicator />', () => {
// Transition to WaitingForConfirmation
rerender(
- <StreamingContext.Provider
- value={{ streamingState: StreamingState.WaitingForConfirmation }}
- >
+ <StreamingContext.Provider value={StreamingState.WaitingForConfirmation}>
<LoadingIndicator
currentLoadingPhrase="Please Confirm"
elapsedTime={15}
@@ -162,9 +153,7 @@ describe('<LoadingIndicator />', () => {
// Transition back to Idle
rerender(
- <StreamingContext.Provider
- value={{ streamingState: StreamingState.Idle }}
- >
+ <StreamingContext.Provider value={StreamingState.Idle}>
<LoadingIndicator {...defaultProps} />
</StreamingContext.Provider>,
);
diff --git a/packages/cli/src/ui/components/LoadingIndicator.tsx b/packages/cli/src/ui/components/LoadingIndicator.tsx
index c3865f3e..31c6fee9 100644
--- a/packages/cli/src/ui/components/LoadingIndicator.tsx
+++ b/packages/cli/src/ui/components/LoadingIndicator.tsx
@@ -22,7 +22,7 @@ export const LoadingIndicator: React.FC<LoadingIndicatorProps> = ({
elapsedTime,
rightContent,
}) => {
- const { streamingState } = useStreamingContext();
+ const streamingState = useStreamingContext();
if (streamingState === StreamingState.Idle) {
return null;
diff --git a/packages/cli/src/ui/components/messages/ToolMessage.test.tsx b/packages/cli/src/ui/components/messages/ToolMessage.test.tsx
index a40ca31b..2b96f18a 100644
--- a/packages/cli/src/ui/components/messages/ToolMessage.test.tsx
+++ b/packages/cli/src/ui/components/messages/ToolMessage.test.tsx
@@ -9,10 +9,7 @@ import { render } from 'ink-testing-library';
import { ToolMessage, ToolMessageProps } from './ToolMessage.js';
import { StreamingState, ToolCallStatus } from '../../types.js';
import { Text } from 'ink';
-import {
- StreamingContext,
- StreamingContextType,
-} from '../../contexts/StreamingContext.js';
+import { StreamingContext } from '../../contexts/StreamingContext.js';
// Mock child components or utilities if they are complex or have side effects
vi.mock('../GeminiRespondingSpinner.js', () => ({
@@ -21,7 +18,7 @@ vi.mock('../GeminiRespondingSpinner.js', () => ({
}: {
nonRespondingDisplay?: string;
}) => {
- const { streamingState } = React.useContext(StreamingContext)!;
+ const streamingState = React.useContext(StreamingContext)!;
if (streamingState === StreamingState.Responding) {
return <Text>MockRespondingSpinner</Text>;
}
@@ -48,7 +45,7 @@ const renderWithContext = (
ui: React.ReactElement,
streamingState: StreamingState,
) => {
- const contextValue: StreamingContextType = { streamingState };
+ const contextValue: StreamingState = streamingState;
return render(
<StreamingContext.Provider value={contextValue}>
{ui}
diff --git a/packages/cli/src/ui/contexts/StreamingContext.tsx b/packages/cli/src/ui/contexts/StreamingContext.tsx
index 6144ed70..8944d682 100644
--- a/packages/cli/src/ui/contexts/StreamingContext.tsx
+++ b/packages/cli/src/ui/contexts/StreamingContext.tsx
@@ -7,15 +7,11 @@
import React, { createContext } from 'react';
import { StreamingState } from '../types.js';
-export interface StreamingContextType {
- streamingState: StreamingState;
-}
-
-export const StreamingContext = createContext<StreamingContextType | undefined>(
+export const StreamingContext = createContext<StreamingState | undefined>(
undefined,
);
-export const useStreamingContext = (): StreamingContextType => {
+export const useStreamingContext = (): StreamingState => {
const context = React.useContext(StreamingContext);
if (context === undefined) {
throw new Error(